Esempio n. 1
0
        private void ProcessMessage(Message obj)
        {
            var message     = obj.Body;
            var messageType = message.GetType();
            var handler     = MessageHandlers.GetFor(messageType);

            if (handler == null)
            {
                switch (UnhandledMessagesPolicy)
                {
                case UnhandledMessagesPolicy.Requeue:
                    _localQueue.SendMessage(obj);
                    break;

                case UnhandledMessagesPolicy.SendToErrorQueue:
                    SendToErrorQueue(obj);
                    break;
                }

                return;
            }

            handler.Handle(message);
            SendReply(obj);
        }
Esempio n. 2
0
        public void SubscribeTo <TMessage>(BusEndpoint publisherEndpoint, Action <TMessage> handler, bool unsubscribeOnStop = true)
            where TMessage : class
        {
            MessageHandlers.Add(handler);
            var subscription = new Subscription(typeof(TMessage), LocalEndpoint, publisherEndpoint, unsubscribeOnStop);

            _subscriptions.Add(subscription);
            Send(new StartSubscriptionRequest(subscription), publisherEndpoint);
        }
Esempio n. 3
0
 public ServiceBus(string localQueueName)
 {
     LocalEndpoint   = new BusEndpoint("", localQueueName);
     MessageHandlers = new MessageHandlers();
     TargetEndpoints = new TargetEndpoints();
     MessageHandlers.Add <StartSubscriptionRequest>(Handle);
     MessageHandlers.Add <EndSubscriptionRequest>(Handle);
     // TODO: Should it be possible to reject a subscription request?
     //MessageHandlers.Add<SubscriptionStarted>(Handle);
     //MessageHandlers.Add<SubscriptionEnded>(Handle);
     _replyGenerators.AddFor <StartSubscriptionRequest>(r => new SubscriptionStarted(r.Subscription));
     _replyGenerators.AddFor <EndSubscriptionRequest>(r => new SubscriptionEnded(r.Subscription));
 }