Skip to content

Commit

Permalink
Rename SendMessage to Send (#41)
Browse files Browse the repository at this point in the history
* Rename EntryList and SendMessage
  • Loading branch information
ericmillin authored Feb 3, 2022
1 parent 21f1134 commit d8e065b
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 40 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,28 @@ record := map[string]interface{}{
"Hello": "World",
}
msg := protocol.NewMessage("tag", record)
err := c.SendMessage(msg)
err := c.Send(msg)
```

### Send a byte-encoded message

```go
raw := protocol.RawMessage(myMessageBytes)
err := c.SendMessage(raw)
err := c.Send(raw)
```

### Message confirmation

The client supports `ack` confirmations as specified by the Fluent protocol. When enabled, `SendMessage` returns once the acknowledgement is received or the timeout is reached.
The client supports `ack` confirmations as specified by the Fluent protocol. When enabled, `Send` returns once the acknowledgement is received or the timeout is reached.

Note: For types other than `RawMessage`, the `SendMessage` function sets the "chunk" option before sending. A `RawMessage` is immutable and must already contain a "chunk" value. The behavior is otherwise identical.
Note: For types other than `RawMessage`, the `Send` function sets the "chunk" option before sending. A `RawMessage` is immutable and must already contain a "chunk" value. The behavior is otherwise identical.

```go
c := client.New(client.ConnectionOptions{
RequireAck: true,
})
//...
err := c.SendMessage(myMsg)
err := c.Send(myMsg)
```

## Performance
Expand All @@ -89,7 +89,7 @@ err := c.SendMessage(myMsg)

You can read more about the benchmarks [here](cmd/bm/README.md).

### SendMessage
### Send

Run on `localhost`. Does not include message creation.

Expand Down
14 changes: 7 additions & 7 deletions cmd/bm/fluent_forward_go/bm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Benchmark_Fluent_Forward_Go_SendOnly(b *testing.B) {
b.ResetTimer()

for i := 0; i < b.N; i++ {
err = c.SendMessage(mne)
err = c.Send(mne)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -60,7 +60,7 @@ func Benchmark_Fluent_Forward_Go_SingleMessage(b *testing.B) {

for i := 0; i < b.N; i++ {
mne := protocol.NewMessage(tagVar, record)
err = c.SendMessage(mne)
err = c.Send(mne)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func Benchmark_Fluent_Forward_Go_SingleMessageAck(b *testing.B) {

for i := 0; i < b.N; i++ {
mne := protocol.NewMessage(tagVar, record)
err = c.SendMessage(mne)
err = c.Send(mne)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func Benchmark_Fluent_Forward_Go_RawMessage(b *testing.B) {

for i := 0; i < b.N; i++ {
rbits := protocol.RawMessage(bits)
err = c.SendMessage(rbits)
err = c.Send(rbits)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -215,7 +215,7 @@ func Benchmark_Fluent_Forward_Go_RawMessageAck(b *testing.B) {

for i := 0; i < b.N; i++ {
rbits := protocol.RawMessage(bits)
err = c.SendMessage(rbits)
err = c.Send(rbits)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -269,7 +269,7 @@ func Benchmark_Fluent_Forward_Go_CompressedMessage(b *testing.B) {

for i := 0; i < b.N; i++ {
mne, _ := protocol.NewCompressedPackedForwardMessage(tagVar, entries)
err = c.SendMessage(mne)
err = c.Send(mne)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -324,7 +324,7 @@ func Benchmark_Fluent_Forward_Go_CompressedMessageAck(b *testing.B) {

for i := 0; i < b.N; i++ {
mne, _ := protocol.NewCompressedPackedForwardMessage(tagVar, entries)
err = c.SendMessage(mne)
err = c.Send(mne)
if err != nil {
b.Fatal(err)
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/forward/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,31 @@ func main() {
compressed, _ := protocol.NewCompressedPackedForwardMessage(tagVar+".compressed",
fwd.Entries)

err = c.SendMessage(msg)
err = c.Send(msg)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

err = c.SendMessage(mne)
err = c.Send(mne)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

err = c.SendMessage(fwd)
err = c.Send(fwd)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

err = c.SendMessage(packedFwd)
err = c.Send(packedFwd)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

err = c.SendMessage(compressed)
err = c.Send(compressed)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -102,7 +102,7 @@ func main() {
b, _ := compressed.MarshalMsg(nil)
rm := protocol.RawMessage(b)

err = c.SendMessage(rm)
err = c.Send(rm)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions cmd/ws/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func main() {
},
}

if err := c.SendMessage(&msg); err != nil {
if err := c.Send(&msg); err != nil {
log.Fatal(err)
}

Expand All @@ -110,7 +110,7 @@ func main() {
},
}

if err := c.SendMessage(&msg); err != nil {
if err := c.Send(&msg); err != nil {
log.Fatal(err)
}

Expand Down
8 changes: 4 additions & 4 deletions fluent/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type MessageClient interface {
Connect() error
Disconnect() (err error)
Reconnect() error
SendMessage(e protocol.ChunkEncoder) error
Send(e protocol.ChunkEncoder) error
SendRaw(raw []byte) error
}

Expand Down Expand Up @@ -175,9 +175,9 @@ func (c *Client) checkAck(chunk string) error {
return nil
}

// SendMessage sends a single protocol.ChunkEncoder across the wire. If the session
// Send sends a single protocol.ChunkEncoder across the wire. If the session
// is not yet in transport phase, an error is returned, and no message is sent.
func (c *Client) SendMessage(e protocol.ChunkEncoder) error {
func (c *Client) Send(e protocol.ChunkEncoder) error {
c.sessionLock.RLock()
defer c.sessionLock.RUnlock()

Expand Down Expand Up @@ -215,7 +215,7 @@ func (c *Client) SendMessage(e protocol.ChunkEncoder) error {
// is not yet in transport phase, an error is returned,
// and no message is sent.
func (c *Client) SendRaw(m []byte) error {
return c.SendMessage(protocol.RawMessage(m))
return c.Send(protocol.RawMessage(m))
}

// Handshake initiates handshake mode. Users must call this before attempting
Expand Down
12 changes: 6 additions & 6 deletions fluent/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var _ = Describe("Client", func() {
})
})

Describe("SendMessage", func() {
Describe("Send", func() {
var (
serverSide net.Conn
msg protocol.MessageExt
Expand Down Expand Up @@ -133,7 +133,7 @@ var _ = Describe("Client", func() {
defer GinkgoRecover()

c <- true
err := client.SendMessage(&msg)
err := client.Send(&msg)
Expect(err).NotTo(HaveOccurred())
}()

Expand All @@ -154,7 +154,7 @@ var _ = Describe("Client", func() {
})

It("Returns an error", func() {
Expect(client.SendMessage(&msg)).To(HaveOccurred())
Expect(client.Send(&msg)).To(HaveOccurred())
})

// TODO: We need a test that no message is sent
Expand Down Expand Up @@ -187,7 +187,7 @@ var _ = Describe("Client", func() {
go func() {
defer GinkgoRecover()
defer func() { done <- true }()
err := client.SendMessage(&msg)
err := client.Send(&msg)
Expect(err).ToNot(HaveOccurred())
}()

Expand All @@ -213,7 +213,7 @@ var _ = Describe("Client", func() {
go func() {
defer GinkgoRecover()
defer func() { done <- true }()
err := client.SendMessage(&msg)
err := client.Send(&msg)
Expect(err.Error()).To(ContainSubstring("Expected chunk"))
}()

Expand Down Expand Up @@ -282,7 +282,7 @@ var _ = Describe("Client", func() {
})

It("Returns an error", func() {
Expect(client.SendMessage(&msg)).To(HaveOccurred())
Expect(client.Send(&msg)).To(HaveOccurred())
})

// TODO: We need a test that no message is sent
Expand Down
4 changes: 2 additions & 2 deletions fluent/client/clientfakes/fake_message_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions fluent/client/ws_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (c *WSClient) connect() error {
}

// Starts the async read. If there is a read error, it is set so that
// it is returned the next time SendMessage is called. That should be
// it is returned the next time Send is called. That should be
// sufficient for most cases where the client cares only about sending.
// If the client really cares about handling reads, they will define a
// custom ReadHandler that will receive the error synchronously.
Expand Down Expand Up @@ -239,8 +239,8 @@ func (c *WSClient) Reconnect() (err error) {
return
}

// SendMessage sends a single msgp.Encodable across the wire.
func (c *WSClient) SendMessage(e protocol.ChunkEncoder) error {
// Send sends a single msgp.Encodable across the wire.
func (c *WSClient) Send(e protocol.ChunkEncoder) error {
// Check for an async connection error and return it here.
// In most cases, the client will not care about reading from
// the connection, so checking for the error here is sufficient.
Expand Down
8 changes: 4 additions & 4 deletions fluent/client/ws_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ var _ = Describe("WSClient", func() {
})
})

Describe("SendMessage", func() {
Describe("Send", func() {
var (
msg protocol.MessageExt
)
Expand All @@ -273,7 +273,7 @@ var _ = Describe("WSClient", func() {

It("Sends the message", func() {
bits, _ := msg.MarshalMsg(nil)
Expect(client.SendMessage(&msg)).ToNot(HaveOccurred())
Expect(client.Send(&msg)).ToNot(HaveOccurred())

writtenbits := conn.WriteArgsForCall(0)
Expect(bytes.Equal(bits, writtenbits)).To(BeTrue())
Expand All @@ -286,7 +286,7 @@ var _ = Describe("WSClient", func() {
})

It("returns an error", func() {
Expect(client.SendMessage(&msg)).To(MatchError("no active session"))
Expect(client.Send(&msg)).To(MatchError("no active session"))
})
})

Expand All @@ -296,7 +296,7 @@ var _ = Describe("WSClient", func() {
})

It("returns the error", func() {
Expect(client.SendMessage(&msg)).To(MatchError("BOOM"))
Expect(client.Send(&msg)).To(MatchError("BOOM"))
})
})
})
Expand Down

0 comments on commit d8e065b

Please sign in to comment.