Skip to content

Commit

Permalink
Merge branch 'main' into feature/integration-2.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	ably/proto_http.go
  • Loading branch information
sacOO7 committed Oct 26, 2023
2 parents 8586ba6 + e66ad6a commit ae5720a
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions ably/internal/ablyutil/msgpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ablyutil
import (
"bytes"
"io"
"reflect"

"github.com/ugorji/go/codec"
)
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions ably/internal/ablyutil/msgpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package ablyutil

import (
"bytes"
"encoding/json"
"testing"
)

Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion ably/proto_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 28 additions & 0 deletions ably/proto_message_decoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ae5720a

Please sign in to comment.