public virtual string AddMessageListener(Action <Message <T> > listener)
        {
            var request = TopicAddMessageListenerCodec.EncodeRequest(GetName(), false);
            DistributedEventHandler handler = m => TopicAddMessageListenerCodec.AbstractEventHandler.Handle(m,
                                                                                                            (item, time, uuid) => HandleMessageListener(item, time, uuid, listener));

            return(Listen(request, m => TopicAddMessageListenerCodec.DecodeResponse(m).response,
                          GetKey(), handler));
        }
Пример #2
0
 public virtual string AddMessageListener(Action<Message<T>> listener)
 {
     var request = TopicAddMessageListenerCodec.EncodeRequest(GetName(), IsSmart());
     DistributedEventHandler handler = m =>
         TopicAddMessageListenerCodec.EventHandler.HandleEvent(m,
             (item, time, uuid) =>
             {
                 HandleMessageListener(item, time, uuid, listener);
             });
     return RegisterListener(request, m => TopicAddMessageListenerCodec.DecodeResponse(m).response,
         id => TopicRemoveMessageListenerCodec.EncodeRequest(GetName(), id), handler);
 }
Пример #3
0
        /// <inheritdoc />
        public async Task <Guid> SubscribeAsync(Action <TopicEventHandlers <T> > handle)
        {
            if (handle == null)
            {
                throw new ArgumentNullException(nameof(handle));
            }

            var handlers = new TopicEventHandlers <T>();

            handle(handlers);

            var subscription = new ClusterSubscription(
                TopicAddMessageListenerCodec.EncodeRequest(Name, Cluster.IsSmartRouting),
                ReadSubscribeResponse,
                CreateUnsubscribeRequest,
                ReadUnsubscribeResponse,
                HandleEventAsync,
                new SubscriptionState <TopicEventHandlers <T> >(Name, handlers));

            await Cluster.Events.InstallSubscriptionAsync(subscription).CAF();

            return(subscription.Id);
        }