public static void Main(string[] args) { _client = BusClientFactory.CreateDefault( cfg => cfg .SetBasePath(Environment.CurrentDirectory) .AddJsonFile("rawrabbit.json"), ioc => ioc .AddSingleton<IConfigurationEvaluator, AttributeConfigEvaluator>() ); _client.SubscribeAsync<ValuesRequested>(ServeValuesAsync); _client.RespondAsync<ValueRequest, ValueResponse>(SendValuesThoughRpcAsync); }
public static Task WithEventHandlerAsync <TEvent>(this IBusClient bus, IEventHandler <TEvent> handler) where TEvent : IEvent => bus.SubscribeAsync <TEvent>(msg => handler.HandleAsync(msg));
public static Task WithCommandHandlerAsync <TCommand>(this IBusClient bus, ICommandHandler <TCommand> handler) where TCommand : ICommand => bus.SubscribeAsync <TCommand>(msg => handler.HandleAsync(msg), contxt => contxt.UseConsumerConfiguration(conf => conf.FromDeclaredQueue(q => q.WithName(GetQueueName <TCommand>()))));
public static ISubscription SubscribeToCommand <TCommand>(this IBusClient bus, ICommandHandler <TCommand> handler, string name = null) where TCommand : ICommand { return(bus.SubscribeAsync <TCommand>(async(msg, context) => await handler.HandleAsync(msg), cfg => cfg.WithQueue(q => q.WithName(GetExchangeName <TCommand>(name))))); }
public void Subscribe() { Bus.SubscribeAsync <UserDeleted>(Consume); }
public static Task WithCommandHandlerAsync <TCommand>(this IBusClient bus, ICommandHandler <TCommand> handler) where TCommand : ICommand { return(bus.SubscribeAsync <TCommand>(msg => handler.HandleAsync(msg), ctx => ctx.UseConsumeConfiguration(q => q.WithConsumerTag(GetQueueName <TCommand>())))); }
// Event Handler Extension Method public static Task WithEventHandlerAsync <TEvent>(this IBusClient bus, IEventHandler <TEvent> handler) where TEvent : IEvent => bus.SubscribeAsync <TEvent>(msg => handler.HandleAsync(msg), context => context.UseSubscribeConfiguration( config => config.FromDeclaredQueue( queue => queue.WithName(GetQueueName <TEvent>()))));
public static Task WithCommandHandlerAsync <TCommand>(this IBusClient bus, ICommandHandler <TCommand> handler) where TCommand : ICommand => bus.SubscribeAsync <TCommand>(msg => handler.HandleAsync(msg), ctx => ctx.UseSubscribeConfiguration(config => config.FromDeclaredQueue(queue => queue.WithName(GetQueueName <TCommand>()))));
public void Subscribe() { Bus.SubscribeAsync <OrderConfirmed>(Consume); }
public static Task WithEventHandlerAsync <TEvent>(this IBusClient bus, IEventHandler <TEvent> handler) where TEvent : IEvent => bus.SubscribeAsync <TEvent>(async message => await handler.HandleAsync(message), context => context.UseConsumerConfiguration(cfg => cfg.FromDeclaredQueue(q => q.WithName(GetQueueName <TEvent>()))));
public void InterceptMessageAsync(Action <string> messagedReceivedAction) { _client.SubscribeAsync <string>(async(message, mc) => { messagedReceivedAction(message); }); }
public void Subscribe() { Bus.SubscribeAsync <RestaurantDeleted>(Consume); }
public static Task WithEventHandlerAsync <TEvent>(this IBusClient bus, IEventHandler <TEvent> handler) where TEvent : IEvent => bus.SubscribeAsync <TEvent>(msg => handler.HandleAsync(msg), ctx => ctx.UseSubscribeConfiguration(cfg => // Multiple instances of same service should subscribe to same single queue. cfg.FromDeclaredQueue(q => q.WithName(GetQueueName <TEvent>()))));
public static void SubscribeToCommand <TCommand>(this IBusClient bus, Func <ICommand, Task> handler) where TCommand : ICommand { bus.SubscribeAsync <TCommand>(msg => handler(msg)); }
public void Subscribe <TEvent, THandler>() where TEvent : IEvent where THandler : IEventHandler <TEvent> => _bus.SubscribeAsync <TEvent>(e => (_provider.GetService(typeof(THandler)) as IEventHandler <TEvent>).Handle(e)).Wait();
public async Task SubscribeAsync <T>(IMessageHandler <T> handler) where T : IMessage => await _bus.SubscribeAsync <T>( msg => handler.HandleAsync(msg), SubscriptionContext(typeof(T), handler.GetType()) );
public Task SubscribeToEventAsync <TEvent>(IEventHandler <TEvent> handler) where TEvent : IEvent { return(_busClient.SubscribeAsync <TEvent>(msg => handler.Handle(msg), context => context.UseConsumeConfiguration(cfg => cfg.FromQueue(GetQueueName <TEvent>())))); }
public static ISubscription WithEventHandlerAsync <TEvent>(this IBusClient bus, IEventHandlerAsync <TEvent> handler, string exchangeName = null, string routingKey = null) where TEvent : IEvent => bus.SubscribeAsync <TEvent>(async(msg, context) => await handler.HandleAsync(msg), cfg => cfg.WithExchange(e => e.WithName(exchangeName)).WithRoutingKey(routingKey));
public static Task WithEventHandlerAsync <TEvent>(this IBusClient bus, IResolver resolver, string name = null) where TEvent : IEvent => bus.SubscribeAsync <TEvent>(msg => resolver.Resolve <IEventHandler <TEvent> >().HandleAsync(msg), ctx => ctx.UseSubscribeConfiguration(cfg => cfg.FromDeclaredQueue(q => q.WithName(GetExchangeName <TEvent>(name)))));
/// <summary> /// Helps to subscribe to a command that goes through the http pipe. /// After subscribing sends the command to the command handler. /// </summary> /// <typeparam name="TCommand">The command type to be subscribed.</typeparam> /// <param name="busClient">The RawRabbit service bus.</param> /// <param name="commandHandler">The command handler</param> /// <returns></returns> public static Task WithCommandHandlerAsync <TCommand>(this IBusClient busClient, ICommandHandler <TCommand> commandHandler) where TCommand : ICommand => busClient.SubscribeAsync <TCommand>(async msg => await commandHandler.HandleAsync(msg), ctx => ctx.UseSubscribeConfiguration(cfg => cfg.FromDeclaredQueue(q => q.WithName(GetQueueName <TCommand>()))));
public static Task WithEventHandlerAsync <TEvent>(this IBusClient _bus, IEventHandler <TEvent> handler) where TEvent : IEvent => _bus.SubscribeAsync <TEvent>(msg => handler.HandleAsync(msg), ctx => ctx.UseSubscribeConfiguration (cfg => cfg.FromDeclaredQueue(q => q.WithName(GetQueueName <TEvent>()))));
public Task SubscribeAsync <TMessage>(IMessageHandler <TMessage> handler, CancellationToken token) => _busClient.SubscribeAsync <TMessage>(message => handler.HandleAsync(message, token), ct: token);
public static Task WithEventHandlerAsync<TEvent>(this IBusClient bus, IEventHandler<TEvent> handler) where TEvent: IEvent => bus.SubscribeAsync<TEvent>(msg => (Task<RawRabbit.Common.Acknowledgement>)handler.HandleAsync(msg), ctx => ctx.UseSubscribeConfiguration(cfg => cfg.FromDeclaredQueue(q => q.WithName(GetQueueName<TEvent>()))));
public static ISubscription WithEventHandlerAsync <TEvent>(this IBusClient bus, IEventHandler <TEvent> handler) where TEvent : IEvent => bus.SubscribeAsync <TEvent>(async(msg, context) => await handler.HandleAsync(msg));
protected override Task ExecuteAsync(CancellationToken stoppingToken) { return(_busClient.SubscribeAsync <NoticeMessage <LotteryTicketed> >(async(message) => { try { _logger.LogInformation("Received ticketing message: {0} {1} Content:{2}", message.LdpMerchanerId, message.LdpOrderId, message.Content); IOrderingApplicationService orderingApplicationService = _iocResolver.GetRequiredService <IOrderingApplicationService>(); IUnitOfWorkManager unitOfWorkManager = _iocResolver.GetRequiredService <IUnitOfWorkManager>(); using (var uow = unitOfWorkManager.Begin()) { if (message.Content.TicketingType == LotteryTicketingTypes.Success) { var order = await orderingApplicationService.TicketedAsync(message.LdpOrderId, message.LdpMerchanerId, message.Content.TicketedNumber, message.Content.TicketedTime, message.Content.TicketedOdds); if (order != null) { await _schedulerManager.EnqueueAsync <ILotteryAwardingScheduler, AwardingScheduleArgs>(new AwardingScheduleArgs { LdpOrderId = message.LdpOrderId, LdpMerchanerId = message.LdpMerchanerId, LvpOrderId = message.Content.LvpOrderId, LvpMerchanerId = message.Content.LvpMerchanerId }, delay: order.ExpectedBonusTime - DateTime.Now); } } else { await orderingApplicationService.RejectedAsync(message.LdpOrderId); } uow.Complete(); return new Ack(); } } catch (Exception ex) { _logger.LogInformation(ex, "Received ticketing message: {0} {1} Content:{2}", message.LdpMerchanerId, message.LdpOrderId, message.Content); } return new Nack(); }, context => { context.UseSubscribeConfiguration(configuration => { configuration.OnDeclaredExchange(exchange => { exchange.WithName("Baibaocp.LotteryNoticing") .WithDurability(true) .WithAutoDelete(false) .WithType(ExchangeType.Topic); }); configuration.FromDeclaredQueue(queue => { queue.WithName("LotteryOrdering.Tickets") .WithAutoDelete(false) .WithDurability(true); }); configuration.Consume(consume => { consume.WithRoutingKey("LotteryOrdering.Ticketed.#"); }); }); }, stoppingToken)); }
public static ISubscription WithCommandHandlerAsync <TCommand>(this IBusClient bus, ICommandHandler <TCommand> handler) where TCommand : ICommand => bus.SubscribeAsync <TCommand>(async(msg, context) => await handler.HandleAsync(msg));
public static Task WithCommandHandlerAsync <TCommand>(this IBusClient bus, ICommandHandler <TCommand> handler) where TCommand : ICommand => bus.SubscribeAsync <TCommand>(msg => handler.HandleAsync(msg));
public static Task WithCommandHandlerAsync <TCommand>(this IBusClient busClient, ICommandHandler <TCommand> handler) where TCommand : ICommand => busClient.SubscribeAsync <TCommand>(message => handler.HandleAsync(message), context => context.UseSubscribeConfiguration(config => config.FromDeclaredQueue(q => q.WithName(GetQueueName <TCommand>()))));