示例#1
0
        public static string Subscribe <TPayload>(
            this IMessageBrokerService messageBrokerService,
            string topic,
            Action <Message <TPayload> > callback,
            Func <Message <TPayload>, bool> filter = null) where TPayload : class
        {
            var id = Guid.NewGuid().ToString();

            var payloadType         = typeof(TPayload).Name;
            var messageSubscription = new MessageSubscription
            {
                Id          = id,
                Topic       = topic,
                PayloadType = typeof(TPayload).Name,
                Callback    = c => callback(new Message <TPayload>(topic, new MessagePayload <TPayload>(payloadType, c.Payload.Content.ToObject <TPayload>())))
            };

            if (filter != null)
            {
                messageSubscription.Filter = c => filter(new Message <TPayload>(topic, new MessagePayload <TPayload>(payloadType, c.Payload.Content.ToObject <TPayload>())));
            }

            messageBrokerService.Subscribe(messageSubscription);

            return(id);
        }
示例#2
0
        public static string Subscribe(
            this IMessageBrokerService messageBrokerService,
            string topic,
            string payloadType,
            Action <Message <JObject> > callback,
            Func <Message <JObject>, bool> filter = null)
        {
            if (messageBrokerService == null)
            {
                throw new ArgumentNullException(nameof(messageBrokerService));
            }
            if (topic == null)
            {
                throw new ArgumentNullException(nameof(topic));
            }
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            var id = Guid.NewGuid().ToString();

            messageBrokerService.Subscribe(new MessageSubscription
            {
                Id          = id,
                Topic       = topic,
                PayloadType = payloadType,
                Filter      = filter,
                Callback    = callback
            });

            return(id);
        }
        public void Subscribe(string id, string topic, string payloadType, string callbackFunctionName)
        {
            var messageSubscription = new MessageSubscription
            {
                Id          = id,
                Topic       = topic,
                PayloadType = payloadType,
                Callback    = m => _scriptingSession.Execute(callbackFunctionName)
            };

            _messageBrokerService.Subscribe(messageSubscription);
        }
示例#4
0
        public static ITrigger CreateTrigger <TPayload>(
            this IMessageBrokerService messageBrokerService,
            string topic,
            Func <Message <TPayload>, bool> filter = null) where TPayload : class
        {
            if (messageBrokerService == null)
            {
                throw new ArgumentNullException(nameof(messageBrokerService));
            }
            if (topic == null)
            {
                throw new ArgumentNullException(nameof(topic));
            }

            var trigger = new Trigger();

            messageBrokerService.Subscribe(topic, c => trigger.Execute(), filter);

            return(trigger);
        }