提交 351d8705 编写于 作者: N neza2017 提交者: zhenshan.cao

fix ttmsgstream (#5689)

* fix msgstream
Signed-off-by: Nyefu.chen <yefu.chen@zilliz.com>

* fix asconsumer
Signed-off-by: Nyefu.chen <yefu.chen@zilliz.com>
上级 c172af78
...@@ -352,6 +352,13 @@ func (ms *mqMsgStream) receiveMsg(consumer mqclient.Consumer) { ...@@ -352,6 +352,13 @@ func (ms *mqMsgStream) receiveMsg(consumer mqclient.Consumer) {
log.Error("Failed to getTsMsgFromConsumerMsg", zap.Error(err)) log.Error("Failed to getTsMsgFromConsumerMsg", zap.Error(err))
continue continue
} }
pos := tsMsg.Position()
tsMsg.SetPosition(&MsgPosition{
ChannelName: pos.ChannelName,
MsgID: pos.MsgID,
MsgGroup: consumer.Subscription(),
Timestamp: tsMsg.BeginTs(),
})
sp, ok := ExtractFromPulsarMsgProperties(tsMsg, msg.Properties()) sp, ok := ExtractFromPulsarMsgProperties(tsMsg, msg.Properties())
if ok { if ok {
...@@ -697,21 +704,12 @@ func (ms *MqTtMsgStream) Seek(msgPositions []*internalpb.MsgPosition) error { ...@@ -697,21 +704,12 @@ func (ms *MqTtMsgStream) Seek(msgPositions []*internalpb.MsgPosition) error {
var mp *MsgPosition var mp *MsgPosition
var err error var err error
fn := func() error { fn := func() error {
if _, ok := ms.consumers[mp.ChannelName]; ok { var ok bool
return fmt.Errorf("the channel should not been subscribed") consumer, ok = ms.consumers[mp.ChannelName]
} if !ok {
return fmt.Errorf("please subcribe the channel, channel name =%s", mp.ChannelName)
receiveChannel := make(chan mqclient.ConsumerMessage, ms.bufSize)
consumer, err = ms.client.Subscribe(mqclient.ConsumerOptions{
Topic: mp.ChannelName,
SubscriptionName: mp.MsgGroup,
SubscriptionInitialPosition: mqclient.SubscriptionPositionEarliest,
Type: mqclient.KeyShared,
MessageChannel: receiveChannel,
})
if err != nil {
return err
} }
if consumer == nil { if consumer == nil {
return fmt.Errorf("consumer is nil") return fmt.Errorf("consumer is nil")
} }
...@@ -736,7 +734,6 @@ func (ms *MqTtMsgStream) Seek(msgPositions []*internalpb.MsgPosition) error { ...@@ -736,7 +734,6 @@ func (ms *MqTtMsgStream) Seek(msgPositions []*internalpb.MsgPosition) error {
if len(mp.MsgID) == 0 { if len(mp.MsgID) == 0 {
return fmt.Errorf("when msgID's length equal to 0, please use AsConsumer interface") return fmt.Errorf("when msgID's length equal to 0, please use AsConsumer interface")
} }
if err = Retry(20, time.Millisecond*200, fn); err != nil { if err = Retry(20, time.Millisecond*200, fn); err != nil {
return fmt.Errorf("Failed to seek, error %s", err.Error()) return fmt.Errorf("Failed to seek, error %s", err.Error())
} }
......
...@@ -254,6 +254,11 @@ func getPulsarTtOutputStreamAndSeek(pulsarAddress string, positions []*MsgPositi ...@@ -254,6 +254,11 @@ func getPulsarTtOutputStreamAndSeek(pulsarAddress string, positions []*MsgPositi
factory := ProtoUDFactory{} factory := ProtoUDFactory{}
pulsarClient, _ := mqclient.NewPulsarClient(pulsar.ClientOptions{URL: pulsarAddress}) pulsarClient, _ := mqclient.NewPulsarClient(pulsar.ClientOptions{URL: pulsarAddress})
outputStream, _ := NewMqTtMsgStream(context.Background(), 100, 100, pulsarClient, factory.NewUnmarshalDispatcher()) outputStream, _ := NewMqTtMsgStream(context.Background(), 100, 100, pulsarClient, factory.NewUnmarshalDispatcher())
consumerName := []string{}
for _, c := range positions {
consumerName = append(consumerName, c.ChannelName)
}
outputStream.AsConsumer(consumerName, positions[0].MsgGroup)
outputStream.Seek(positions) outputStream.Seek(positions)
outputStream.Start() outputStream.Start()
return outputStream return outputStream
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册