Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public static Task WithEventHandlerAsync <TEvent>(this IBusClient bus,
                                                   IEventHandler <TEvent> handler) where TEvent : IEvent
 => bus.SubscribeAsync <TEvent>(msg => handler.HandleAsync(msg));
Exemplo n.º 3
0
 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)))));
 }
Exemplo n.º 5
0
 public void Subscribe()
 {
     Bus.SubscribeAsync <UserDeleted>(Consume);
 }
Exemplo n.º 6
0
 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>()))));
 }
Exemplo n.º 7
0
 // 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>()))));
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 10
0
 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>()))));
Exemplo n.º 11
0
 public void InterceptMessageAsync(Action <string> messagedReceivedAction)
 {
     _client.SubscribeAsync <string>(async(message, mc) => {
         messagedReceivedAction(message);
     });
 }
Exemplo n.º 12
0
 public void Subscribe()
 {
     Bus.SubscribeAsync <RestaurantDeleted>(Consume);
 }
Exemplo n.º 13
0
 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>()))));
Exemplo n.º 14
0
 public static void SubscribeToCommand <TCommand>(this IBusClient bus, Func <ICommand, Task> handler) where TCommand : ICommand
 {
     bus.SubscribeAsync <TCommand>(msg => handler(msg));
 }
Exemplo n.º 15
0
 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();
Exemplo n.º 16
0
 public async Task SubscribeAsync <T>(IMessageHandler <T> handler) where T : IMessage
 => await _bus.SubscribeAsync <T>(
     msg => handler.HandleAsync(msg),
     SubscriptionContext(typeof(T), handler.GetType())
     );
Exemplo n.º 17
0
 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>()))));
 }
Exemplo n.º 18
0
 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));
Exemplo n.º 19
0
 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)))));
Exemplo n.º 20
0
 /// <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>()))));
Exemplo n.º 21
0
 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);
Exemplo n.º 23
0
 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>()))));
Exemplo n.º 24
0
 public static ISubscription WithEventHandlerAsync <TEvent>(this IBusClient bus,
                                                            IEventHandler <TEvent> handler) where TEvent : IEvent
 => bus.SubscribeAsync <TEvent>(async(msg, context) => await handler.HandleAsync(msg));
Exemplo n.º 25
0
 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));
 }
Exemplo n.º 26
0
 public static ISubscription WithCommandHandlerAsync <TCommand>(this IBusClient bus,
                                                                ICommandHandler <TCommand> handler) where TCommand : ICommand
 => bus.SubscribeAsync <TCommand>(async(msg, context) => await handler.HandleAsync(msg));
Exemplo n.º 27
0
 public static Task WithCommandHandlerAsync <TCommand>(this IBusClient bus,
                                                       ICommandHandler <TCommand> handler) where TCommand : ICommand
 => bus.SubscribeAsync <TCommand>(msg => handler.HandleAsync(msg));
Exemplo n.º 28
0
 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>()))));