Ejemplo n.º 1
0
        private void OnMessage(TimeoutMessage message, IDeliveryContext context)
        {
            Console.WriteLine("[Consumer] Received message: {0}", message.JobId);
            Thread.Sleep(8000);
            Console.WriteLine("[Consumer] Processed message: {0}", message.JobId);

            context.Reply(new TimeoutResponse());
        }
Ejemplo n.º 2
0
        public void Start()
        {
            isRunning = true;

            // create a subscription to timeout messages 
            // with a custom timeout subscription topology
            var subscription = bus.Subscribe<TimeoutMessage>(
                OnMessageTimeout,
                s => s.SetTopology<TimeoutSubscriptionTopology>());

            // get the name of our subscription queue
            var timeoutSubscriptionQueueName = subscription.Queues[0].Name;

            // this subscription should never be fired
            // create a subscription to timeout messages 
            // with a custom timeout subscription topology
            bus.Subscribe<TimeoutMessage>(
                OnMessageTimeoutAlt,
                s => s.SetTopology<TimeoutSubscriptionTopology>());

            // create a standard requester
            using (var requester = bus.CreateRequester<TimeoutMessage, TimeoutResponse>())
            {
                while (isRunning)
                {
                    Console.WriteLine("[Publisher] Publishing new timeout message");

                    // set the routing key on each message to the subscription
                    // queue name, this will route our timeout message to our
                    // timeout subscription
                    var message = new TimeoutMessage
                    {
                        JobId = Guid.NewGuid().ToString(),
                        RoutingKey = timeoutSubscriptionQueueName
                    };

                    requester.Request(message, OnResponse);
                    Thread.Sleep(3000);
                }
            }
        }
Ejemplo n.º 3
0
 private void OnMessageTimeoutAlt(TimeoutMessage message)
 {
     throw new Exception("Other timeout subscriber, should never be called");
 }
Ejemplo n.º 4
0
 private void OnMessageTimeout(TimeoutMessage message)
 {
     Console.WriteLine("[Publisher] MESSAGE TIMEDOUT: {0}", message.JobId);
 }