mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-01 00:15:30 +08:00
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package rmq
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/milvus-io/milvus/pkg/v2/mq/mqimpl/rocksmq/client"
|
|
"github.com/milvus-io/milvus/pkg/v2/streaming/util/types"
|
|
"github.com/milvus-io/milvus/pkg/v2/streaming/walimpls"
|
|
"github.com/milvus-io/milvus/pkg/v2/streaming/walimpls/helper"
|
|
)
|
|
|
|
var _ walimpls.OpenerImpls = (*openerImpl)(nil)
|
|
|
|
// openerImpl is the implementation of walimpls.Opener interface.
|
|
type openerImpl struct {
|
|
c client.Client
|
|
}
|
|
|
|
// Open opens a new wal.
|
|
func (o *openerImpl) Open(ctx context.Context, opt *walimpls.OpenOption) (walimpls.WALImpls, error) {
|
|
if err := opt.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
var p client.Producer
|
|
if opt.Channel.AccessMode == types.AccessModeRW {
|
|
var err error
|
|
if p, err = o.c.CreateProducer(client.ProducerOptions{
|
|
Topic: opt.Channel.Name,
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return &walImpl{
|
|
WALHelper: helper.NewWALHelper(opt),
|
|
p: p,
|
|
c: o.c,
|
|
}, nil
|
|
}
|
|
|
|
// Close closes the opener resources.
|
|
func (o *openerImpl) Close() {
|
|
o.c.Close()
|
|
}
|