Lin, Il giorno mer 8 set 2021 alle ore 07:34 linlin <lin...@apache.org> ha scritto:
> # Motivation > > There are many users who need to use tag messages. The implementation of > this part has also been discussed before: > > > https://lists.apache.org/list.html?*@pulsar.apache.org:lte=2y:Proposal%20for%20Consumer%20Filtering%20in%20Pulsar%20brokers > > I suggest to plug-in the Dispatcher, so that users can not only develop tag > messages, but also customize their own delayed messages and other features. > I also share this problem, because if you want to efficiently implement message filtering you need to do it in the broker side. I am not sure that making the full Dispatcher pluggable is a good idea, because the code is too complex and also it really depends on the internals of the Broker. If we make this pluggable that we must define a limited private but "stable" API. My suggestion is to define particular needs and then add features to make pluggable single specific parts of the dispatcher. For instance I would add some support for "Message filtering", leaving the implementation of the "filter" to a plugin. This way you could implement filtering using JMS rules, or using other metadata or security related information Regards Enrico > > Plug-in Dispatcher has no compatibility impact on existing Brokers. > > # Modifications > > 1. > > Add a configuration item `dispatcherProviderClassName`,the creation of > an existing Dispatcher will be moved to DefaultDispatcherProvider, as > the > default class. > 2. > > Add a new Interface DispatcherProvider > > > public interface DispatcherProvider { > > > > // Use `DispatcherProvider` to create `Dispatcher` > > Dispatcher createDispatcher(Consumer consumer, Subscription > subscription); > > static DispatcherProvider createDispatcherProvider(ServiceConfiguration > serviceConfiguration) { > > // According to `dispatcherProviderClassName`, create Provider through > reflection > > } > > } > > We can get BrokerService from Subscription, and then Pulsar from > BrokerService, so the parameters of this interface must be sufficient. > > DispatcherProvider will be created when the subscription is initialized: > > ``` > > DispatcherProvider.createDispatcherProvider(config); > > ``` > > When there is a Consumer subscription, we will create a Dispatcher: > > dispatcher = dispatcherProvider.createDispatcher(consumer, this); > > I opened a new PR: > > https://github.com/apache/pulsar/pull/11948 >