2021-11-04 11:12:03 +00:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-04-19 03:30:19 +00:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-04 11:12:03 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 03:30:19 +00:00
|
|
|
//
|
2021-11-04 11:12:03 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2021-04-19 03:30:19 +00:00
|
|
|
|
2021-04-02 05:48:25 +00:00
|
|
|
package msgstream
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-04-07 14:05:32 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2022-03-24 02:15:25 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
|
|
|
|
2022-03-03 13:57:56 +00:00
|
|
|
rmqimplserver "github.com/milvus-io/milvus/internal/mq/mqimpl/rocksmq/server"
|
|
|
|
|
2021-04-02 05:48:25 +00:00
|
|
|
"github.com/apache/pulsar-client-go/pulsar"
|
2022-04-07 14:05:32 +00:00
|
|
|
|
2022-03-03 13:57:56 +00:00
|
|
|
puslarmqwrapper "github.com/milvus-io/milvus/internal/mq/msgstream/mqwrapper/pulsar"
|
|
|
|
rmqwrapper "github.com/milvus-io/milvus/internal/mq/msgstream/mqwrapper/rmq"
|
2021-04-02 05:48:25 +00:00
|
|
|
)
|
|
|
|
|
2021-09-23 13:57:55 +00:00
|
|
|
// PmsFactory is a pulsar msgstream factory that implemented Factory interface(msgstream.go)
|
2021-04-02 05:48:25 +00:00
|
|
|
type PmsFactory struct {
|
|
|
|
dispatcherFactory ProtoUDFactory
|
|
|
|
// the following members must be public, so that mapstructure.Decode() can access them
|
|
|
|
PulsarAddress string
|
|
|
|
ReceiveBufSize int64
|
|
|
|
PulsarBufSize int64
|
|
|
|
}
|
|
|
|
|
2022-04-07 14:05:32 +00:00
|
|
|
func NewPmsFactory(config *paramtable.PulsarConfig) *PmsFactory {
|
|
|
|
return &PmsFactory{
|
|
|
|
PulsarBufSize: 1024,
|
|
|
|
ReceiveBufSize: 1024,
|
|
|
|
PulsarAddress: config.Address,
|
|
|
|
}
|
2021-04-02 05:48:25 +00:00
|
|
|
}
|
|
|
|
|
2021-09-23 13:57:55 +00:00
|
|
|
// NewMsgStream is used to generate a new Msgstream object
|
2021-04-02 05:48:25 +00:00
|
|
|
func (f *PmsFactory) NewMsgStream(ctx context.Context) (MsgStream, error) {
|
2022-03-03 13:57:56 +00:00
|
|
|
pulsarClient, err := puslarmqwrapper.NewClient(pulsar.ClientOptions{URL: f.PulsarAddress})
|
2021-04-02 05:48:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return NewMqMsgStream(ctx, f.ReceiveBufSize, f.PulsarBufSize, pulsarClient, f.dispatcherFactory.NewUnmarshalDispatcher())
|
|
|
|
}
|
|
|
|
|
2021-09-23 13:57:55 +00:00
|
|
|
// NewTtMsgStream is used to generate a new TtMsgstream object
|
2021-04-02 05:48:25 +00:00
|
|
|
func (f *PmsFactory) NewTtMsgStream(ctx context.Context) (MsgStream, error) {
|
2022-03-03 13:57:56 +00:00
|
|
|
pulsarClient, err := puslarmqwrapper.NewClient(pulsar.ClientOptions{URL: f.PulsarAddress})
|
2021-04-02 05:48:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return NewMqTtMsgStream(ctx, f.ReceiveBufSize, f.PulsarBufSize, pulsarClient, f.dispatcherFactory.NewUnmarshalDispatcher())
|
|
|
|
}
|
|
|
|
|
2021-09-23 13:57:55 +00:00
|
|
|
// NewQueryMsgStream is used to generate a new QueryMsgstream object
|
2021-04-02 05:48:25 +00:00
|
|
|
func (f *PmsFactory) NewQueryMsgStream(ctx context.Context) (MsgStream, error) {
|
|
|
|
return f.NewMsgStream(ctx)
|
|
|
|
}
|
|
|
|
|
2021-09-23 13:57:55 +00:00
|
|
|
// RmsFactory is a rocksmq msgstream factory that implemented Factory interface(msgstream.go)
|
2021-04-02 05:48:25 +00:00
|
|
|
type RmsFactory struct {
|
|
|
|
dispatcherFactory ProtoUDFactory
|
|
|
|
// the following members must be public, so that mapstructure.Decode() can access them
|
|
|
|
ReceiveBufSize int64
|
|
|
|
RmqBufSize int64
|
|
|
|
}
|
|
|
|
|
2021-09-23 13:57:55 +00:00
|
|
|
// NewMsgStream is used to generate a new Msgstream object
|
2021-04-02 05:48:25 +00:00
|
|
|
func (f *RmsFactory) NewMsgStream(ctx context.Context) (MsgStream, error) {
|
2022-03-03 13:57:56 +00:00
|
|
|
rmqClient, err := rmqwrapper.NewClientWithDefaultOptions()
|
2021-04-02 05:48:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return NewMqMsgStream(ctx, f.ReceiveBufSize, f.RmqBufSize, rmqClient, f.dispatcherFactory.NewUnmarshalDispatcher())
|
|
|
|
}
|
|
|
|
|
2021-09-23 13:57:55 +00:00
|
|
|
// NewTtMsgStream is used to generate a new TtMsgstream object
|
2021-04-02 05:48:25 +00:00
|
|
|
func (f *RmsFactory) NewTtMsgStream(ctx context.Context) (MsgStream, error) {
|
2022-03-03 13:57:56 +00:00
|
|
|
rmqClient, err := rmqwrapper.NewClientWithDefaultOptions()
|
2021-04-02 05:48:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return NewMqTtMsgStream(ctx, f.ReceiveBufSize, f.RmqBufSize, rmqClient, f.dispatcherFactory.NewUnmarshalDispatcher())
|
|
|
|
}
|
|
|
|
|
2021-09-23 13:57:55 +00:00
|
|
|
// NewQueryMsgStream is used to generate a new QueryMsgstream object
|
2021-04-02 05:48:25 +00:00
|
|
|
func (f *RmsFactory) NewQueryMsgStream(ctx context.Context) (MsgStream, error) {
|
2022-03-03 13:57:56 +00:00
|
|
|
rmqClient, err := rmqwrapper.NewClientWithDefaultOptions()
|
2021-06-26 14:26:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return NewMqMsgStream(ctx, f.ReceiveBufSize, f.RmqBufSize, rmqClient, f.dispatcherFactory.NewUnmarshalDispatcher())
|
2021-04-02 05:48:25 +00:00
|
|
|
}
|
|
|
|
|
2021-09-23 13:57:55 +00:00
|
|
|
// NewRmsFactory is used to generate a new RmsFactory object
|
2022-04-07 14:05:32 +00:00
|
|
|
func NewRmsFactory(path string) *RmsFactory {
|
2021-04-02 05:48:25 +00:00
|
|
|
f := &RmsFactory{
|
|
|
|
dispatcherFactory: ProtoUDFactory{},
|
|
|
|
ReceiveBufSize: 1024,
|
|
|
|
RmqBufSize: 1024,
|
|
|
|
}
|
2022-04-07 14:05:32 +00:00
|
|
|
err := rmqimplserver.InitRocksMQ(path)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("init rmq error", zap.Error(err))
|
|
|
|
}
|
2021-04-02 05:48:25 +00:00
|
|
|
return f
|
|
|
|
}
|