Skip to content

Commit

Permalink
Add flag to disable forced topic creation. (apache#226)
Browse files Browse the repository at this point in the history
This flag is needed for the regex consumer.
  • Loading branch information
cckellogg authored Apr 25, 2020
1 parent 0f822ef commit 6edc8f4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
32 changes: 17 additions & 15 deletions pulsar/consumer_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ type acker interface {

type consumer struct {
sync.Mutex
topic string
client *client
options ConsumerOptions
consumers []*partitionConsumer
consumerName string
topic string
client *client
options ConsumerOptions
consumers []*partitionConsumer
consumerName string
disableForceTopicCreation bool

// channel used to deliver message to clients
messageCh chan ConsumerMessage
Expand Down Expand Up @@ -123,17 +124,18 @@ func newConsumer(client *client, options ConsumerOptions) (Consumer, error) {
}

func newInternalConsumer(client *client, options ConsumerOptions, topic string,
messageCh chan ConsumerMessage, dlq *dlqRouter) (*consumer, error) {
messageCh chan ConsumerMessage, dlq *dlqRouter, disableForceTopicCreation bool) (*consumer, error) {

consumer := &consumer{
topic: topic,
client: client,
options: options,
messageCh: messageCh,
closeCh: make(chan struct{}),
errorCh: make(chan error),
dlq: dlq,
log: log.WithField("topic", topic),
topic: topic,
client: client,
options: options,
disableForceTopicCreation: disableForceTopicCreation,
messageCh: messageCh,
closeCh: make(chan struct{}),
errorCh: make(chan error),
dlq: dlq,
log: log.WithField("topic", topic),
}

if options.Name != "" {
Expand Down Expand Up @@ -275,7 +277,7 @@ func (c *consumer) internalTopicSubscribeToPartitions() error {

func topicSubscribe(client *client, options ConsumerOptions, topic string,
messageCh chan ConsumerMessage, dlqRouter *dlqRouter) (Consumer, error) {
return newInternalConsumer(client, options, topic, messageCh, dlqRouter)
return newInternalConsumer(client, options, topic, messageCh, dlqRouter, false)
}

func (c *consumer) Subscription() string {
Expand Down
7 changes: 7 additions & 0 deletions pulsar/consumer_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type partitionConsumerOpts struct {
startMessageIDInclusive bool
subscriptionMode subscriptionMode
readCompacted bool
disableForceTopicCreation bool
}

type partitionConsumer struct {
Expand Down Expand Up @@ -748,6 +749,12 @@ func (pc *partitionConsumer) grabConn() error {
cmdSubscribe.Metadata = toKeyValues(pc.options.metadata)
}

// force topic creation is enabled by default so
// we only need to set the flag when disabling it
if pc.options.disableForceTopicCreation {
cmdSubscribe.ForceTopicCreation = proto.Bool(false)
}

res, err := pc.client.rpcClient.Request(lr.LogicalAddr, lr.PhysicalAddr, requestID,
pb.BaseCommand_SUBSCRIBE, cmdSubscribe)

Expand Down
2 changes: 1 addition & 1 deletion pulsar/consumer_regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func subscriber(c *client, topics []string, opts ConsumerOptions, ch chan Consum
for _, t := range topics {
go func(topic string) {
defer wg.Done()
c, err := newInternalConsumer(c, opts, topic, ch, dlq)
c, err := newInternalConsumer(c, opts, topic, ch, dlq, true)
consumerErrorCh <- consumerError{
err: err,
topic: topic,
Expand Down

0 comments on commit 6edc8f4

Please sign in to comment.