mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-03 04:19:18 +08:00
Change receive msg logic (#5605)
Signed-off-by: godchen <qingxiang.chen@zilliz.com>
This commit is contained in:
parent
0a82c6381f
commit
91ef35bad4
@ -58,22 +58,7 @@ func (pc *pulsarClient) Subscribe(options ConsumerOptions) (Consumer, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
msgChannel := make(chan ConsumerMessage)
|
||||
pConsumer := &pulsarConsumer{c: consumer, msgChannel: msgChannel}
|
||||
|
||||
go func() {
|
||||
for { //nolint:gosimple
|
||||
select {
|
||||
case msg, ok := <-pConsumer.c.Chan():
|
||||
if !ok {
|
||||
close(msgChannel)
|
||||
log.Debug("pulsar consumer channel closed")
|
||||
return
|
||||
}
|
||||
msgChannel <- &pulsarMessage{msg: msg}
|
||||
}
|
||||
}
|
||||
}()
|
||||
pConsumer := &pulsarConsumer{c: consumer}
|
||||
|
||||
return pConsumer, nil
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ package mqclient
|
||||
|
||||
import (
|
||||
"github.com/apache/pulsar-client-go/pulsar"
|
||||
"github.com/milvus-io/milvus/internal/log"
|
||||
)
|
||||
|
||||
type pulsarConsumer struct {
|
||||
@ -25,6 +26,22 @@ func (pc *pulsarConsumer) Subscription() string {
|
||||
}
|
||||
|
||||
func (pc *pulsarConsumer) Chan() <-chan ConsumerMessage {
|
||||
if pc.msgChannel == nil {
|
||||
pc.msgChannel = make(chan ConsumerMessage)
|
||||
go func() {
|
||||
for { //nolint:gosimple
|
||||
select {
|
||||
case msg, ok := <-pc.c.Chan():
|
||||
if !ok {
|
||||
close(pc.msgChannel)
|
||||
log.Debug("pulsar consumer channel closed")
|
||||
return
|
||||
}
|
||||
pc.msgChannel <- &pulsarMessage{msg: msg}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
return pc.msgChannel
|
||||
}
|
||||
|
||||
|
@ -55,22 +55,8 @@ func (rc *rmqClient) Subscribe(options ConsumerOptions) (Consumer, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
msgChannel := make(chan ConsumerMessage, 1)
|
||||
rConsumer := &rmqConsumer{c: cli, msgChannel: msgChannel}
|
||||
rConsumer := &rmqConsumer{c: cli}
|
||||
|
||||
go func() {
|
||||
for { //nolint:gosimple
|
||||
select {
|
||||
case msg, ok := <-rConsumer.c.Chan():
|
||||
if !ok {
|
||||
close(msgChannel)
|
||||
return
|
||||
}
|
||||
msg.Topic = options.Topic
|
||||
msgChannel <- &rmqMessage{msg: msg}
|
||||
}
|
||||
}
|
||||
}()
|
||||
return rConsumer, nil
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,22 @@ func (rc *rmqConsumer) Subscription() string {
|
||||
}
|
||||
|
||||
func (rc *rmqConsumer) Chan() <-chan ConsumerMessage {
|
||||
|
||||
if rc.msgChannel == nil {
|
||||
rc.msgChannel = make(chan ConsumerMessage)
|
||||
go func() {
|
||||
for { //nolint:gosimple
|
||||
select {
|
||||
case msg, ok := <-rc.c.Chan():
|
||||
if !ok {
|
||||
close(rc.msgChannel)
|
||||
return
|
||||
}
|
||||
rc.msgChannel <- &rmqMessage{msg: msg}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
return rc.msgChannel
|
||||
}
|
||||
|
||||
|
@ -134,6 +134,7 @@ func consume(ctx context.Context, consumer *consumer) {
|
||||
consumer.messageCh <- ConsumerMessage{
|
||||
MsgID: msg[0].MsgID,
|
||||
Payload: msg[0].Payload,
|
||||
Topic: consumer.Topic(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user