add pub sub md5

This commit is contained in:
Chris Lu
2020-05-09 00:43:53 -07:00
parent 07d7abe428
commit d693e77418
3 changed files with 27 additions and 6 deletions

View File

@@ -1,6 +1,8 @@
package msgclient
import (
"crypto/md5"
"hash"
"io"
"log"
@@ -13,6 +15,7 @@ import (
type PubChannel struct {
client messaging_pb.SeaweedMessaging_PublishClient
grpcConnection *grpc.ClientConn
md5hash hash.Hash
}
func (mc *MessagingClient) NewPubChannel(chanName string) (*PubChannel, error) {
@@ -32,15 +35,20 @@ func (mc *MessagingClient) NewPubChannel(chanName string) (*PubChannel, error) {
return &PubChannel{
client: pc,
grpcConnection: grpcConnection,
md5hash: md5.New(),
}, nil
}
func (pc *PubChannel) Publish(m []byte) error {
return pc.client.Send(&messaging_pb.PublishRequest{
err := pc.client.Send(&messaging_pb.PublishRequest{
Data: &messaging_pb.Message{
Value: m,
},
})
if err == nil {
pc.md5hash.Write(m)
}
return err
}
func (pc *PubChannel) Close() error {
@@ -62,3 +70,7 @@ func (pc *PubChannel) Close() error {
}
return nil
}
func (pc *PubChannel) Md5() []byte {
return pc.md5hash.Sum(nil)
}