diff --git a/CHANGELOG.md b/CHANGELOG.md index c48371cc..5c82c2f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log -# Changelog +## [1.2.14](https://github.com/ably/ably-go/tree/1.2.14) + +[Full Changelog](https://github.com/ably/ably-go/compare/v1.2.13...v1.2.14) + +**Merged pull requests:** + +- Fix message extras unmarshaled to incompatible json type [\#624](https://github.com/ably/ably-go/pull/624) ([zknill](https://github.com/zknill)) ## [1.2.13](https://github.com/ably/ably-go/tree/1.2.13) diff --git a/README.md b/README.md index 7d1159f3..7fe03763 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ if err != nil { #### Update MaxMessageSize/read limit for realtime message subscription - The default `MaxMessageSize` is automatically configured by Ably when connection is established with Ably. -- This value defaults to 64kb, please [get in touch](https://ably.com/support) if you would like to request a higher limit for your account. +- This value defaults to [16kb for free and 64kb for PAYG account](https://faqs.ably.com/what-is-the-maximum-message-size), please [get in touch](https://ably.com/support) if you would like to request a higher limit for your account. - Upgrading your account to higher limit will automatically update `MaxMessageSize` property and should accordingly set the client side connection read limit. - If you are still facing issues when receiving large messages or intentionally want to reduce the limit, you can explicitly update the connection read limit: @@ -325,6 +325,34 @@ if err != nil { } fmt.Print(status, status.ChannelId) ``` + +### Configure logging +- By default, internal logger prints output to `stdout` with default logging level of `warning`. +- You need to create a custom Logger that implements `ably.Logger` interface. +- There is also an option provided to configure loglevel. + +```go +type customLogger struct { + *log.Logger +} + +func (s *customLogger) Printf(level ably.LogLevel, format string, v ...interface{}) { + s.Logger.Printf(fmt.Sprintf("[%s] %s", level, format), v...) +} + +func NewCustomLogger() *customLogger { + logger := &customLogger{} + logger.Logger = log.New(os.Stdout, "", log.LstdFlags) + return logger +} + +client, err = ably.NewRealtime( + ably.WithKey("xxx:xxx"), + ably.WithLogHandler(NewCustomLogger()), + ably.WithLogLevel(ably.LogWarning), +) +``` + ## Note on usage of ablytest package Although the `ablytest` package is available as a part of ably-go, we do not recommend using it as a sandbox for your own testing, since it's specifically intended for client library SDKs and we don’t provide any guarantees for support or that it will remain publicly accessible. It can lead to unexpected behaviour, since some beta features may be deployed on the `sandbox` environment so that they can be tested before going into production. diff --git a/ably/internal/ablyutil/msgpack.go b/ably/internal/ablyutil/msgpack.go index 98dd66ce..ae19ce1c 100644 --- a/ably/internal/ablyutil/msgpack.go +++ b/ably/internal/ablyutil/msgpack.go @@ -3,6 +3,7 @@ package ablyutil import ( "bytes" "io" + "reflect" "github.com/ugorji/go/codec" ) @@ -13,6 +14,7 @@ func init() { handle.Raw = true handle.WriteExt = true handle.RawToString = true + handle.MapType = reflect.TypeOf(map[string]interface{}(nil)) } // UnmarshalMsgpack decodes the MessagePack-encoded data and stores the result in the diff --git a/ably/internal/ablyutil/msgpack_test.go b/ably/internal/ablyutil/msgpack_test.go index 59e98cef..0b35ff0e 100644 --- a/ably/internal/ablyutil/msgpack_test.go +++ b/ably/internal/ablyutil/msgpack_test.go @@ -5,6 +5,7 @@ package ablyutil import ( "bytes" + "encoding/json" "testing" ) @@ -31,3 +32,28 @@ func TestMsgpack(t *testing.T) { } }) } + +func TestMsgpackJson(t *testing.T) { + extras := map[string]interface{}{ + "headers": map[string]interface{}{ + "version": 1, + }, + } + + b, err := MarshalMsgpack(extras) + if err != nil { + t.Fatal(err) + } + + var got map[string]interface{} + err = UnmarshalMsgpack(b, &got) + if err != nil { + t.Fatal(err) + } + + buff := bytes.Buffer{} + err = json.NewEncoder(&buff).Encode(got) + if err != nil { + t.Fatal(err) + } +} diff --git a/ably/proto_http.go b/ably/proto_http.go index cf4e1fad..2a57df07 100644 --- a/ably/proto_http.go +++ b/ably/proto_http.go @@ -11,7 +11,7 @@ const ( ablyProtocolVersionHeader = "X-Ably-Version" ablyErrorCodeHeader = "X-Ably-Errorcode" ablyErrorMessageHeader = "X-Ably-Errormessage" - clientLibraryVersion = "1.2.12" + clientLibraryVersion = "1.2.14" clientRuntimeName = "go" ablyProtocolVersion = "2" // CSV2 ablyClientIDHeader = "X-Ably-ClientId" diff --git a/ably/proto_message_decoding_test.go b/ably/proto_message_decoding_test.go index 060e7408..f96d5a48 100644 --- a/ably/proto_message_decoding_test.go +++ b/ably/proto_message_decoding_test.go @@ -107,6 +107,34 @@ func loadMsgpackFixtures() ([]MsgpackTestFixture, error) { return o, err } +func TestMsgpackExtrasJsonCompatible(t *testing.T) { + p := protocolMessage{ + Messages: []*Message{ + { + Name: "my event", + Data: "hello world", + Extras: map[string]interface{}{ + "headers": map[string]interface{}{ + "version": 1, + }, + }, + }, + }, + } + + b, err := ablyutil.MarshalMsgpack(p) + assert.NoError(t, err) + + var got ProtocolMessage + assert.NoError(t, ablyutil.UnmarshalMsgpack(b, &got)) + + msg, err := got.Messages[0].withDecodedData(nil) + assert.NoError(t, err) + + buff := bytes.Buffer{} + assert.NoError(t, json.NewEncoder(&buff).Encode(msg)) +} + func TestMsgpackDecoding(t *testing.T) { msgpackTestFixtures, err := loadMsgpackFixtures() require.NoError(t, err)