mirror of
https://github.com/fhmq/hmq.git
synced 2026-08-28 21:43:11 +00:00
update queue shub
This commit is contained in:
+92
-25
@@ -3,6 +3,7 @@
|
||||
package broker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
@@ -387,7 +388,16 @@ func (b *Broker) removeClient(c *client) {
|
||||
b.clients.Delete(clientId)
|
||||
}
|
||||
|
||||
func (b *Broker) PublishMessage(packet *packets.PublishPacket, deliver bool) {
|
||||
func (b *Broker) OnlineOfflineNotification(clientID string, online bool) {
|
||||
packet := packets.NewControlPacket(packets.Publish).(*packets.PublishPacket)
|
||||
packet.TopicName = "$SYS/broker/connection/clients/" + clientID
|
||||
packet.Qos = 0
|
||||
packet.Payload = []byte(fmt.Sprintf(`{"clientID":"%s","online":%v,"timestamp":"%s"}`, clientID, online, time.Now().UTC().Format(time.RFC3339)))
|
||||
|
||||
b.PublishMessage(packet)
|
||||
}
|
||||
|
||||
func (b *Broker) PublishDeliverdMessage(packet *packets.PublishPacket, share bool) {
|
||||
{
|
||||
//do retain
|
||||
if packet.Retain {
|
||||
@@ -397,13 +407,6 @@ func (b *Broker) PublishMessage(packet *packets.PublishPacket, deliver bool) {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
//deliver message to other node
|
||||
if deliver {
|
||||
go b.DeliverMessage(packet)
|
||||
}
|
||||
}
|
||||
|
||||
var subs []interface{}
|
||||
var qoss []byte
|
||||
err := b.topicsMgr.Subscribers([]byte(packet.TopicName), packet.Qos, &subs, &qoss)
|
||||
@@ -416,33 +419,97 @@ func (b *Broker) PublishMessage(packet *packets.PublishPacket, deliver bool) {
|
||||
return
|
||||
}
|
||||
|
||||
var qsub []int
|
||||
for i, sub := range subs {
|
||||
var qsub []*subscription
|
||||
for _, sub := range subs {
|
||||
s, ok := sub.(*subscription)
|
||||
if ok {
|
||||
if s.share {
|
||||
qsub = append(qsub, i)
|
||||
qsub = append(qsub, s)
|
||||
} else {
|
||||
publish(s, packet)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if len(qsub) > 0 {
|
||||
idx := r.Intn(len(qsub))
|
||||
sub := subs[qsub[idx]].(*subscription)
|
||||
if share {
|
||||
target := r.Intn(len(qsub))
|
||||
sub := qsub[target]
|
||||
publish(sub, packet)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Broker) PublishMessage(packet *packets.PublishPacket) {
|
||||
{
|
||||
//do retain
|
||||
if packet.Retain {
|
||||
if err := b.topicsMgr.Retain(packet); err != nil {
|
||||
log.Error("Error retaining message: ", zap.Error(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var subs []interface{}
|
||||
var qoss []byte
|
||||
err := b.topicsMgr.Subscribers([]byte(packet.TopicName), packet.Qos, &subs, &qoss)
|
||||
if err != nil {
|
||||
log.Error("search sub client error, ", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
if len(subs) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var qsub []*subscription
|
||||
for _, sub := range subs {
|
||||
s, ok := sub.(*subscription)
|
||||
if ok {
|
||||
if s.share {
|
||||
qsub = append(qsub, s)
|
||||
} else {
|
||||
publish(s, packet)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b.ProcessRemote(packet, qsub)
|
||||
|
||||
}
|
||||
|
||||
func (b *Broker) ProcessRemote(packet *packets.PublishPacket, loaclShareSub []*subscription) {
|
||||
shareRemoteID := ""
|
||||
remoteSubInfo := b.QuerySubscribe(packet.TopicName, packet.Qos)
|
||||
totalShare := len(loaclShareSub)
|
||||
for _, v := range remoteSubInfo {
|
||||
totalShare = totalShare + v.shareSubCount
|
||||
}
|
||||
target := r.Intn(totalShare)
|
||||
|
||||
if target < len(loaclShareSub) {
|
||||
shareRemoteID = b.id
|
||||
} else {
|
||||
target = target - len(loaclShareSub)
|
||||
for k, v := range remoteSubInfo {
|
||||
if target < v.shareSubCount {
|
||||
shareRemoteID = k
|
||||
return
|
||||
}
|
||||
target = target - v.shareSubCount
|
||||
}
|
||||
}
|
||||
|
||||
//send remote
|
||||
for id, sub := range remoteSubInfo {
|
||||
rpcCli := b.rpcClient[id]
|
||||
if sub.subCount > 0 {
|
||||
rpcCli.DeliverMessage(context.Background(), &pb.DeliverMessageRequest{Topic: packet.TopicName, Payload: packet.Payload, Share: shareRemoteID == id})
|
||||
}
|
||||
}
|
||||
|
||||
//send local
|
||||
if shareRemoteID == b.id {
|
||||
sub := loaclShareSub[target]
|
||||
publish(sub, packet)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (b *Broker) OnlineOfflineNotification(clientID string, online bool) {
|
||||
packet := packets.NewControlPacket(packets.Publish).(*packets.PublishPacket)
|
||||
packet.TopicName = "$SYS/broker/connection/clients/" + clientID
|
||||
packet.Qos = 0
|
||||
packet.Payload = []byte(fmt.Sprintf(`{"clientID":"%s","online":%v,"timestamp":"%s"}`, clientID, online, time.Now().UTC().Format(time.RFC3339)))
|
||||
|
||||
b.PublishMessage(packet, true)
|
||||
}
|
||||
|
||||
+3
-3
@@ -228,7 +228,7 @@ func (c *client) processClientPublish(packet *packets.PublishPacket) {
|
||||
|
||||
switch packet.Qos {
|
||||
case QosAtMostOnce:
|
||||
c.broker.PublishMessage(packet, true)
|
||||
c.broker.PublishMessage(packet)
|
||||
case QosAtLeastOnce:
|
||||
puback := packets.NewControlPacket(packets.Puback).(*packets.PubackPacket)
|
||||
puback.MessageID = packet.MessageID
|
||||
@@ -236,7 +236,7 @@ func (c *client) processClientPublish(packet *packets.PublishPacket) {
|
||||
log.Error("send puback error, ", zap.Error(err), zap.String("ClientID", c.info.clientID))
|
||||
return
|
||||
}
|
||||
c.broker.PublishMessage(packet, true)
|
||||
c.broker.PublishMessage(packet)
|
||||
case QosExactlyOnce:
|
||||
return
|
||||
default:
|
||||
@@ -439,7 +439,7 @@ func (c *client) Close() {
|
||||
//offline notification
|
||||
b.OnlineOfflineNotification(c.info.clientID, false)
|
||||
if c.info.willMsg != nil {
|
||||
b.PublishMessage(c.info.willMsg, true)
|
||||
b.PublishMessage(c.info.willMsg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -11,6 +11,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/fhmq/hmq/logger"
|
||||
"go.uber.org/zap"
|
||||
@@ -73,7 +74,6 @@ func ConfigureConfig(args []string) (*Config, error) {
|
||||
fs.StringVar(&config.Port, "port", "1883", "Port to listen on.")
|
||||
fs.StringVar(&config.Port, "p", "1883", "Port to listen on.")
|
||||
fs.StringVar(&config.Host, "host", "0.0.0.0", "Network host to listen on")
|
||||
fs.StringVar(&config.RpcPort, "rpc", "10011", "Port to listen on.")
|
||||
fs.StringVar(&config.Router, "r", "", "Router who maintenance cluster info")
|
||||
fs.StringVar(&config.Router, "router", "", "Router who maintenance cluster info")
|
||||
fs.StringVar(&config.WsPort, "ws", "", "port for ws to listen on")
|
||||
@@ -164,6 +164,11 @@ func (config *Config) check() error {
|
||||
config.TlsHost = "0.0.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
if config.Router != "" {
|
||||
config.RpcPort = strconv.Itoa(randInt())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -205,3 +210,7 @@ func NewTLSConfig(tlsInfo TLSInfo) (*tls.Config, error) {
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
func randInt() int {
|
||||
return r.Intn(1000) + 10000
|
||||
}
|
||||
|
||||
+25
-60
@@ -48,8 +48,8 @@ type HMQ struct {
|
||||
b *Broker
|
||||
}
|
||||
|
||||
func (h *HMQ) QuerySubscribe(ctx context.Context, in *pb.QuerySubscribeRequest) (*pb.Response, error) {
|
||||
resp := &pb.Response{
|
||||
func (h *HMQ) QuerySubscribe(ctx context.Context, in *pb.QuerySubscribeRequest) (*pb.SubscribeResponse, error) {
|
||||
resp := &pb.SubscribeResponse{
|
||||
RetCode: 0,
|
||||
}
|
||||
topic := in.Topic
|
||||
@@ -71,6 +71,18 @@ func (h *HMQ) QuerySubscribe(ctx context.Context, in *pb.QuerySubscribeRequest)
|
||||
if len(subs) == 0 {
|
||||
resp.RetCode = 404
|
||||
}
|
||||
resp.SubCount = int32(len(subs))
|
||||
|
||||
var qsub int32
|
||||
for _, sub := range subs {
|
||||
s, ok := sub.(*subscription)
|
||||
if ok {
|
||||
if s.share {
|
||||
qsub++
|
||||
}
|
||||
}
|
||||
}
|
||||
resp.ShareSubCount = qsub
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
@@ -96,7 +108,7 @@ func (h *HMQ) DeliverMessage(ctx context.Context, in *pb.DeliverMessageRequest)
|
||||
p.TopicName = in.Topic
|
||||
p.Payload = in.Payload
|
||||
p.Retain = false
|
||||
b.PublishMessage(p, false)
|
||||
b.PublishDeliverdMessage(p, in.Share)
|
||||
|
||||
resp := &pb.Response{
|
||||
RetCode: 0,
|
||||
@@ -104,57 +116,8 @@ func (h *HMQ) DeliverMessage(ctx context.Context, in *pb.DeliverMessageRequest)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (h *HMQ) QueryShareSubscribe(ctx context.Context, in *pb.QueryShareSubscribeRequest) (*pb.ShareSubscribeResponse, error) {
|
||||
resp := &pb.ShareSubscribeResponse{
|
||||
RetCode: 0,
|
||||
}
|
||||
topic := in.Topic
|
||||
qos := in.Qos
|
||||
if qos > 1 {
|
||||
resp.RetCode = 404
|
||||
return resp, nil
|
||||
}
|
||||
func (b *Broker) DeliverMessage(packet *packets.PublishPacket, shareRemoteID string) {
|
||||
|
||||
b := h.b
|
||||
var qoss []byte
|
||||
var subs []interface{}
|
||||
err := b.topicsMgr.Subscribers([]byte(topic), byte(qos), &subs, &qoss)
|
||||
if err != nil {
|
||||
log.Error("search sub client error, ", zap.Error(err))
|
||||
resp.RetCode = 404
|
||||
}
|
||||
|
||||
if len(subs) == 0 {
|
||||
resp.RetCode = 404
|
||||
}
|
||||
|
||||
var qsub int32
|
||||
for _, sub := range subs {
|
||||
s, ok := sub.(*subscription)
|
||||
if ok {
|
||||
if s.share {
|
||||
qsub++
|
||||
}
|
||||
}
|
||||
}
|
||||
resp.ShareSubCount = qsub
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (b *Broker) DeliverMessage(packet *packets.PublishPacket) {
|
||||
for _, client := range b.rpcClient {
|
||||
|
||||
resp, err := client.QuerySubscribe(context.Background(), &pb.QuerySubscribeRequest{Topic: packet.TopicName, Qos: int32(packet.Qos)})
|
||||
if err != nil {
|
||||
log.Error("rpc request error:", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
|
||||
if resp.RetCode == 0 {
|
||||
client.DeliverMessage(context.Background(), &pb.DeliverMessageRequest{Topic: packet.TopicName, Payload: packet.Payload})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Broker) QueryConnect(clientID string) {
|
||||
@@ -163,18 +126,20 @@ func (b *Broker) QueryConnect(clientID string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Broker) QueryShareSubscribe(topic string, qos byte) map[string]int32 {
|
||||
result := make(map[string]int32)
|
||||
type remoteSubInfo struct {
|
||||
subCount int
|
||||
shareSubCount int
|
||||
}
|
||||
|
||||
func (b *Broker) QuerySubscribe(topic string, qos byte) map[string]remoteSubInfo {
|
||||
result := make(map[string]remoteSubInfo)
|
||||
for id, client := range b.rpcClient {
|
||||
resp, err := client.QueryShareSubscribe(context.Background(), &pb.QueryShareSubscribeRequest{Topic: topic, Qos: int32(qos)})
|
||||
resp, err := client.QuerySubscribe(context.Background(), &pb.QuerySubscribeRequest{Topic: topic, Qos: int32(qos)})
|
||||
if err != nil {
|
||||
log.Error("rpc request error:", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
if resp.ShareSubCount > 0 {
|
||||
result[id] = resp.ShareSubCount
|
||||
}
|
||||
|
||||
result[id] = remoteSubInfo{subCount: int(resp.SubCount), shareSubCount: int(resp.ShareSubCount)}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ Logging Options:
|
||||
|
||||
Cluster Options:
|
||||
-r, --router <rurl> Router who maintenance cluster info
|
||||
-rpc, <rpc-port> Cluster listen port for others
|
||||
|
||||
Common Options:
|
||||
-h, --help Show this message
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
"port": "1883",
|
||||
"host": "0.0.0.0",
|
||||
"debug": true,
|
||||
"rpc": "10011",
|
||||
"router": "127.0.0.1:9888",
|
||||
"tlsPort": "8883",
|
||||
"tlsHost": "0.0.0.0",
|
||||
|
||||
@@ -26,7 +26,6 @@ require (
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80
|
||||
golang.org/x/sys v0.0.0-20190730183949-1393eb018365 // indirect
|
||||
golang.org/x/text v0.3.2 // indirect
|
||||
google.golang.org/appengine v1.4.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20190716160619-c506a9f90610 // indirect
|
||||
google.golang.org/grpc v1.22.1
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||
|
||||
+61
-129
@@ -114,6 +114,7 @@ type DeliverMessageRequest struct {
|
||||
Topic string `protobuf:"bytes,1,opt,name=Topic,proto3" json:"Topic,omitempty"`
|
||||
Payload []byte `protobuf:"bytes,2,opt,name=Payload,proto3" json:"Payload,omitempty"`
|
||||
Qos int32 `protobuf:"varint,3,opt,name=Qos,proto3" json:"Qos,omitempty"`
|
||||
Share bool `protobuf:"varint,4,opt,name=Share,proto3" json:"Share,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
@@ -165,51 +166,11 @@ func (m *DeliverMessageRequest) GetQos() int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
type QueryShareSubscribeRequest struct {
|
||||
Topic string `protobuf:"bytes,1,opt,name=Topic,proto3" json:"Topic,omitempty"`
|
||||
Qos int32 `protobuf:"varint,2,opt,name=Qos,proto3" json:"Qos,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *QueryShareSubscribeRequest) Reset() { *m = QueryShareSubscribeRequest{} }
|
||||
func (m *QueryShareSubscribeRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*QueryShareSubscribeRequest) ProtoMessage() {}
|
||||
func (*QueryShareSubscribeRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_935f0990d4a84183, []int{3}
|
||||
}
|
||||
|
||||
func (m *QueryShareSubscribeRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_QueryShareSubscribeRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *QueryShareSubscribeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_QueryShareSubscribeRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *QueryShareSubscribeRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_QueryShareSubscribeRequest.Merge(m, src)
|
||||
}
|
||||
func (m *QueryShareSubscribeRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_QueryShareSubscribeRequest.Size(m)
|
||||
}
|
||||
func (m *QueryShareSubscribeRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_QueryShareSubscribeRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_QueryShareSubscribeRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *QueryShareSubscribeRequest) GetTopic() string {
|
||||
func (m *DeliverMessageRequest) GetShare() bool {
|
||||
if m != nil {
|
||||
return m.Topic
|
||||
return m.Share
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *QueryShareSubscribeRequest) GetQos() int32 {
|
||||
if m != nil {
|
||||
return m.Qos
|
||||
}
|
||||
return 0
|
||||
return false
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
@@ -224,7 +185,7 @@ func (m *Response) Reset() { *m = Response{} }
|
||||
func (m *Response) String() string { return proto.CompactTextString(m) }
|
||||
func (*Response) ProtoMessage() {}
|
||||
func (*Response) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_935f0990d4a84183, []int{4}
|
||||
return fileDescriptor_935f0990d4a84183, []int{3}
|
||||
}
|
||||
|
||||
func (m *Response) XXX_Unmarshal(b []byte) error {
|
||||
@@ -259,55 +220,63 @@ func (m *Response) GetMessage() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
type ShareSubscribeResponse struct {
|
||||
type SubscribeResponse struct {
|
||||
RetCode int32 `protobuf:"varint,1,opt,name=RetCode,proto3" json:"RetCode,omitempty"`
|
||||
Message string `protobuf:"bytes,2,opt,name=Message,proto3" json:"Message,omitempty"`
|
||||
ShareSubCount int32 `protobuf:"varint,3,opt,name=ShareSubCount,proto3" json:"ShareSubCount,omitempty"`
|
||||
SubCount int32 `protobuf:"varint,3,opt,name=SubCount,proto3" json:"SubCount,omitempty"`
|
||||
ShareSubCount int32 `protobuf:"varint,4,opt,name=ShareSubCount,proto3" json:"ShareSubCount,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *ShareSubscribeResponse) Reset() { *m = ShareSubscribeResponse{} }
|
||||
func (m *ShareSubscribeResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*ShareSubscribeResponse) ProtoMessage() {}
|
||||
func (*ShareSubscribeResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_935f0990d4a84183, []int{5}
|
||||
func (m *SubscribeResponse) Reset() { *m = SubscribeResponse{} }
|
||||
func (m *SubscribeResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*SubscribeResponse) ProtoMessage() {}
|
||||
func (*SubscribeResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_935f0990d4a84183, []int{4}
|
||||
}
|
||||
|
||||
func (m *ShareSubscribeResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_ShareSubscribeResponse.Unmarshal(m, b)
|
||||
func (m *SubscribeResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_SubscribeResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *ShareSubscribeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_ShareSubscribeResponse.Marshal(b, m, deterministic)
|
||||
func (m *SubscribeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_SubscribeResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *ShareSubscribeResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_ShareSubscribeResponse.Merge(m, src)
|
||||
func (m *SubscribeResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_SubscribeResponse.Merge(m, src)
|
||||
}
|
||||
func (m *ShareSubscribeResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_ShareSubscribeResponse.Size(m)
|
||||
func (m *SubscribeResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_SubscribeResponse.Size(m)
|
||||
}
|
||||
func (m *ShareSubscribeResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_ShareSubscribeResponse.DiscardUnknown(m)
|
||||
func (m *SubscribeResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_SubscribeResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_ShareSubscribeResponse proto.InternalMessageInfo
|
||||
var xxx_messageInfo_SubscribeResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *ShareSubscribeResponse) GetRetCode() int32 {
|
||||
func (m *SubscribeResponse) GetRetCode() int32 {
|
||||
if m != nil {
|
||||
return m.RetCode
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *ShareSubscribeResponse) GetMessage() string {
|
||||
func (m *SubscribeResponse) GetMessage() string {
|
||||
if m != nil {
|
||||
return m.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *ShareSubscribeResponse) GetShareSubCount() int32 {
|
||||
func (m *SubscribeResponse) GetSubCount() int32 {
|
||||
if m != nil {
|
||||
return m.SubCount
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *SubscribeResponse) GetShareSubCount() int32 {
|
||||
if m != nil {
|
||||
return m.ShareSubCount
|
||||
}
|
||||
@@ -318,35 +287,34 @@ func init() {
|
||||
proto.RegisterType((*QuerySubscribeRequest)(nil), "QuerySubscribeRequest")
|
||||
proto.RegisterType((*QueryConnectRequest)(nil), "QueryConnectRequest")
|
||||
proto.RegisterType((*DeliverMessageRequest)(nil), "DeliverMessageRequest")
|
||||
proto.RegisterType((*QueryShareSubscribeRequest)(nil), "QueryShareSubscribeRequest")
|
||||
proto.RegisterType((*Response)(nil), "Response")
|
||||
proto.RegisterType((*ShareSubscribeResponse)(nil), "ShareSubscribeResponse")
|
||||
proto.RegisterType((*SubscribeResponse)(nil), "SubscribeResponse")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("hmq.proto", fileDescriptor_935f0990d4a84183) }
|
||||
|
||||
var fileDescriptor_935f0990d4a84183 = []byte{
|
||||
// 312 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0xc1, 0x4f, 0xc2, 0x30,
|
||||
0x14, 0xc6, 0x99, 0x04, 0x65, 0x2f, 0x48, 0x4c, 0x05, 0x24, 0xf3, 0x42, 0x1a, 0x0f, 0x9c, 0x9a,
|
||||
0xa0, 0xe1, 0xaa, 0x87, 0x71, 0xd0, 0x03, 0x89, 0x2b, 0x5e, 0x3c, 0x6e, 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 0x1b, 0x38, 0x37, 0x69, 0xbe,
|
||||
0x28, 0x32, 0x5d, 0xef, 0x6b, 0xff, 0xbc, 0xfd, 0x70, 0x00, 0x1e, 0x97, 0xc1, 0x0a, 0xe5, 0x2e,
|
||||
0x89, 0x91, 0xcc, 0xa1, 0x6f, 0x73, 0x25, 0x23, 0xd6, 0x08, 0xda, 0x73, 0x99, 0x69, 0x47, 0x5b,
|
||||
0x64, 0x06, 0xbd, 0x9f, 0x34, 0xc9, 0x80, 0x35, 0xc0, 0xb5, 0x2d, 0x73, 0xe8, 0xdb, 0x34, 0xc9,
|
||||
0x88, 0x35, 0xe2, 0xb5, 0x6d, 0xcb, 0xfa, 0xdd, 0xd8, 0x17, 0x45, 0xae, 0xd9, 0xdf, 0xfc, 0xbc,
|
||||
0x2b, 0xd6, 0x7c, 0xad, 0xb4, 0x15, 0x9d, 0x56, 0xcf, 0xf9, 0xee, 0x33, 0x00, 0x00, 0xff, 0xff,
|
||||
0x82, 0x90, 0x64, 0x25, 0xdb, 0x02, 0x00, 0x00,
|
||||
// 317 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0xc1, 0x4e, 0xf2, 0x40,
|
||||
0x14, 0x85, 0xff, 0xf9, 0x01, 0xa5, 0x37, 0x48, 0x74, 0x04, 0xd2, 0xb0, 0x22, 0x13, 0x17, 0xac,
|
||||
0x26, 0x41, 0xe3, 0x16, 0x17, 0x65, 0xa1, 0x0b, 0x12, 0x99, 0xfa, 0x02, 0x6d, 0xb9, 0x91, 0x26,
|
||||
0xd8, 0x29, 0x33, 0x53, 0x12, 0x1e, 0xc1, 0x17, 0xf2, 0xf9, 0x4c, 0x87, 0xb6, 0x69, 0x63, 0x13,
|
||||
0x13, 0x77, 0xfd, 0xda, 0xb9, 0xe7, 0x9c, 0xde, 0x33, 0xe0, 0xec, 0x3e, 0x0e, 0x3c, 0x55, 0xd2,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47, 0x75,
|
||||
0x8c, 0x23, 0xa4, 0x4b, 0x18, 0x36, 0xfb, 0xa3, 0x13, 0xde, 0x5a, 0xe8, 0x94, 0xf2, 0x1f, 0xbf,
|
||||
0xc0, 0xfe, 0xd1, 0x05, 0x0c, 0xea, 0xf5, 0xd1, 0x11, 0x6f, 0x69, 0x73, 0xea, 0xf0, 0xda, 0xc8,
|
||||
0x23, 0x0c, 0x9b, 0xf5, 0xd1, 0x09, 0x6f, 0xed, 0xb3, 0x31, 0x16, 0x5e, 0xd8, 0x0b, 0xf7, 0xf0,
|
||||
0x1d, 0x00, 0x00, 0xff, 0xff, 0x97, 0x25, 0x6c, 0x83, 0x7d, 0x02, 0x00, 0x00,
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
@@ -361,10 +329,9 @@ const _ = grpc.SupportPackageIsVersion4
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
|
||||
type HMQServiceClient interface {
|
||||
QuerySubscribe(ctx context.Context, in *QuerySubscribeRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
QuerySubscribe(ctx context.Context, in *QuerySubscribeRequest, opts ...grpc.CallOption) (*SubscribeResponse, error)
|
||||
QueryConnect(ctx context.Context, in *QueryConnectRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
DeliverMessage(ctx context.Context, in *DeliverMessageRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
QueryShareSubscribe(ctx context.Context, in *QueryShareSubscribeRequest, opts ...grpc.CallOption) (*ShareSubscribeResponse, error)
|
||||
}
|
||||
|
||||
type hMQServiceClient struct {
|
||||
@@ -375,8 +342,8 @@ func NewHMQServiceClient(cc *grpc.ClientConn) HMQServiceClient {
|
||||
return &hMQServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *hMQServiceClient) QuerySubscribe(ctx context.Context, in *QuerySubscribeRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
out := new(Response)
|
||||
func (c *hMQServiceClient) QuerySubscribe(ctx context.Context, in *QuerySubscribeRequest, opts ...grpc.CallOption) (*SubscribeResponse, error) {
|
||||
out := new(SubscribeResponse)
|
||||
err := c.cc.Invoke(ctx, "/HMQService/QuerySubscribe", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -402,28 +369,18 @@ func (c *hMQServiceClient) DeliverMessage(ctx context.Context, in *DeliverMessag
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *hMQServiceClient) QueryShareSubscribe(ctx context.Context, in *QueryShareSubscribeRequest, opts ...grpc.CallOption) (*ShareSubscribeResponse, error) {
|
||||
out := new(ShareSubscribeResponse)
|
||||
err := c.cc.Invoke(ctx, "/HMQService/QueryShareSubscribe", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// HMQServiceServer is the server API for HMQService service.
|
||||
type HMQServiceServer interface {
|
||||
QuerySubscribe(context.Context, *QuerySubscribeRequest) (*Response, error)
|
||||
QuerySubscribe(context.Context, *QuerySubscribeRequest) (*SubscribeResponse, error)
|
||||
QueryConnect(context.Context, *QueryConnectRequest) (*Response, error)
|
||||
DeliverMessage(context.Context, *DeliverMessageRequest) (*Response, error)
|
||||
QueryShareSubscribe(context.Context, *QueryShareSubscribeRequest) (*ShareSubscribeResponse, error)
|
||||
}
|
||||
|
||||
// UnimplementedHMQServiceServer can be embedded to have forward compatible implementations.
|
||||
type UnimplementedHMQServiceServer struct {
|
||||
}
|
||||
|
||||
func (*UnimplementedHMQServiceServer) QuerySubscribe(ctx context.Context, req *QuerySubscribeRequest) (*Response, error) {
|
||||
func (*UnimplementedHMQServiceServer) QuerySubscribe(ctx context.Context, req *QuerySubscribeRequest) (*SubscribeResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method QuerySubscribe not implemented")
|
||||
}
|
||||
func (*UnimplementedHMQServiceServer) QueryConnect(ctx context.Context, req *QueryConnectRequest) (*Response, error) {
|
||||
@@ -432,9 +389,6 @@ func (*UnimplementedHMQServiceServer) QueryConnect(ctx context.Context, req *Que
|
||||
func (*UnimplementedHMQServiceServer) DeliverMessage(ctx context.Context, req *DeliverMessageRequest) (*Response, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeliverMessage not implemented")
|
||||
}
|
||||
func (*UnimplementedHMQServiceServer) QueryShareSubscribe(ctx context.Context, req *QueryShareSubscribeRequest) (*ShareSubscribeResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method QueryShareSubscribe not implemented")
|
||||
}
|
||||
|
||||
func RegisterHMQServiceServer(s *grpc.Server, srv HMQServiceServer) {
|
||||
s.RegisterService(&_HMQService_serviceDesc, srv)
|
||||
@@ -494,24 +448,6 @@ func _HMQService_DeliverMessage_Handler(srv interface{}, ctx context.Context, de
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _HMQService_QueryShareSubscribe_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(QueryShareSubscribeRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(HMQServiceServer).QueryShareSubscribe(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/HMQService/QueryShareSubscribe",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(HMQServiceServer).QueryShareSubscribe(ctx, req.(*QueryShareSubscribeRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var _HMQService_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "HMQService",
|
||||
HandlerType: (*HMQServiceServer)(nil),
|
||||
@@ -528,10 +464,6 @@ var _HMQService_serviceDesc = grpc.ServiceDesc{
|
||||
MethodName: "DeliverMessage",
|
||||
Handler: _HMQService_DeliverMessage_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "QueryShareSubscribe",
|
||||
Handler: _HMQService_QueryShareSubscribe_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "hmq.proto",
|
||||
|
||||
+5
-9
@@ -13,11 +13,7 @@ message DeliverMessageRequest {
|
||||
string Topic = 1;
|
||||
bytes Payload = 2;
|
||||
int32 Qos = 3;
|
||||
}
|
||||
|
||||
message QueryShareSubscribeRequest {
|
||||
string Topic = 1;
|
||||
int32 Qos = 2;
|
||||
bool Share =4;
|
||||
}
|
||||
|
||||
message Response {
|
||||
@@ -25,16 +21,16 @@ message Response {
|
||||
string Message = 2;
|
||||
}
|
||||
|
||||
message ShareSubscribeResponse {
|
||||
message SubscribeResponse {
|
||||
int32 RetCode = 1;
|
||||
string Message = 2;
|
||||
int32 ShareSubCount = 3;
|
||||
int32 SubCount = 3;
|
||||
int32 ShareSubCount = 4;
|
||||
}
|
||||
|
||||
//Service define
|
||||
service HMQService {
|
||||
rpc QuerySubscribe(QuerySubscribeRequest) returns (Response) {}
|
||||
rpc QuerySubscribe(QuerySubscribeRequest) returns (SubscribeResponse) {}
|
||||
rpc QueryConnect(QueryConnectRequest) returns (Response) {}
|
||||
rpc DeliverMessage(DeliverMessageRequest) returns (Response) {}
|
||||
rpc QueryShareSubscribe(QueryShareSubscribeRequest) returns (ShareSubscribeResponse) {}
|
||||
}
|
||||
Reference in New Issue
Block a user