public IHandlerRegistration Add <T>(Action <IMessage <T>, MessageReceivedInfo> handler) where T : class { Preconditions.CheckNotNull(handler, "handler"); Add <T>((message, info) => TaskHelpers.ExecuteSynchronously(() => handler(message, info))); return(this); }
public static QueueConsumerPair Create <T>(IQueue queue, Action <IMessage <T>, MessageReceivedInfo> onMessage) where T : class { Preconditions.CheckNotNull(queue, nameof(queue)); Preconditions.CheckNotNull(onMessage, nameof(onMessage)); return(Create <T>(queue, (message, info) => TaskHelpers.ExecuteSynchronously(() => onMessage(message, info)))); }
public When_a_consumer_has_multiple_handlers() { mockBuilder = new MockBuilder(); var queue = new Queue("test_queue", false); var countdownEvent = new CountdownEvent(3); mockBuilder.Bus.Advanced.Consume(queue, x => x .Add <MyMessage>((message, info) => TaskHelpers.ExecuteSynchronously(() => { myMessageResult = message.Body; countdownEvent.Signal(); })) .Add <MyOtherMessage>((message, info) => TaskHelpers.ExecuteSynchronously(() => { myOtherMessageResult = message.Body; countdownEvent.Signal(); })) .Add <IAnimal>((message, info) => TaskHelpers.ExecuteSynchronously(() => { animalResult = message.Body; countdownEvent.Signal(); }))); Deliver(new MyMessage { Text = "Hello Polymorphs!" }); Deliver(new MyOtherMessage { Text = "Hello Isomorphs!" }); Deliver(new Dog()); countdownEvent.Wait(1000); }
public static QueueConsumerPair Consume(IQueue queue, Action <byte[], MessageProperties, MessageReceivedInfo> onMessage) { Preconditions.CheckNotNull(queue, nameof(queue)); Preconditions.CheckNotNull(onMessage, nameof(onMessage)); return(new QueueConsumerPair(queue, (bytes, properties, info) => TaskHelpers.ExecuteSynchronously(() => onMessage(bytes, properties, info)), null)); }
public IHandlerRegistration Add <T>(Action <T> handler) where T : class { Preconditions.CheckNotNull(handler, "handler"); this.Add <T>(message => TaskHelpers.ExecuteSynchronously(() => handler(message))); return(this); }
public IDisposable Receive <T>(string queue, Action <T> onMessage) where T : class { Preconditions.CheckNotNull(queue, "queue"); Preconditions.CheckNotNull(onMessage, "onMessage"); return(Receive <T>(queue, message => TaskHelpers.ExecuteSynchronously(() => onMessage(message)))); }
public IDisposable Consume <T>(IQueue queue, Action <IMessage <T>, MessageReceivedInfo> onMessage, Action <IConsumerConfiguration> configure) where T : class { Preconditions.CheckNotNull(queue, "queue"); Preconditions.CheckNotNull(onMessage, "onMessage"); Preconditions.CheckNotNull(configure, "configure"); return(Consume <T>(queue, (message, info) => TaskHelpers.ExecuteSynchronously(() => onMessage(message, info)), configure)); }
public ISubscriptionResult Subscribe <T>( string subscriptionId, Action <T> onMessage, Action <ISubscriptionConfiguration> configure = null) where T : class { return(SubscribeAsync <T>( subscriptionId, msg => TaskHelpers.ExecuteSynchronously(() => onMessage(msg)), configure)); }
public static IDisposable Subscribe( this IBus bus, Type messageType, Action <object> onMessage, Action <ISubscriptionConfiguration> configure) { Preconditions.CheckNotNull(onMessage, "onMessage"); Func <object, Task> asyncOnMessage = x => TaskHelpers.ExecuteSynchronously(() => onMessage(x)); return(SubscribeAsync(bus, messageType, asyncOnMessage, configure)); }
public static Func <byte[], MessageProperties, MessageReceivedInfo, Task> GetConsumeActionWrapper(HandlerRegistration handlerRegistration, IDependencyResolver dependencyResolver) { Func <byte[], MessageProperties, MessageReceivedInfo, Task> consumeAction = (body, messageProps, info) => { var bodyString = Encoding.UTF8.GetString(body); var messageConent = typeof(string) == handlerRegistration.MessageType ? bodyString : JsonConvert.DeserializeObject(bodyString, handlerRegistration.MessageType, SerializerSettings); Logger.Debug("Message {0} recieved with content {1}", handlerRegistration.MessageType, bodyString); var message = Message.CreateInstance(handlerRegistration.MessageType, messageConent); message.SetProperties(messageProps); return (TaskHelpers.ExecuteSynchronously( () => GetHandler(message, handlerRegistration.GetConsumerContextFunc, handlerRegistration.Consumer, dependencyResolver))); }; return(consumeAction); }
public IHandlerRegistration Add <T>(Action <IMessage <T>, MessageReceivedInfo> handler) where T : class { Add <T>((message, info) => TaskHelpers.ExecuteSynchronously(() => handler(message, info))); return(this); }
public IDisposable Consume(IQueue queue, Action <byte[], MessageProperties, MessageReceivedInfo> onMessage, Action <IConsumerConfiguration> configure) { return(Consume(queue, (bytes, properties, info) => TaskHelpers.ExecuteSynchronously(() => onMessage(bytes, properties, info)), configure)); }
public IDisposable Receive <T>(string queue, Action <T> onMessage, Action <IConsumerConfiguration> configure = null) where T : class { return(ReceiveAsync <T>(queue, message => TaskHelpers.ExecuteSynchronously(() => onMessage(message)), configure)); }