public TestRMQListener(RmqMessagingGatewayConnection connection, string channelName) { _channelName = channelName; _connectionFactory = new ConnectionFactory { Uri = connection.AmpqUri.Uri.ToString() }; _connection = _connectionFactory.CreateConnection(); _channel = _connection.CreateModel(); _channel.DeclareExchangeForConnection(connection); _channel.QueueDeclare(_channelName, false, false, false, null); _channel.QueueBind(_channelName, connection.Exchange.Name, _channelName); }
public DispatchBuilderWithNamedGateway() { var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory((_) => new MyEventMessageMapper())); messageMapperRegistry.Register <MyEvent, MyEventMessageMapper>(); var policyRegistry = new PolicyRegistry { { CommandProcessor.RETRYPOLICY, Policy .Handle <Exception>() .WaitAndRetry(new[] { TimeSpan.FromMilliseconds(50) }) }, { CommandProcessor.CIRCUITBREAKER, Policy .Handle <Exception>() .CircuitBreaker(1, TimeSpan.FromMilliseconds(500)) } }; var connection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange") }; var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(connection); var container = new ServiceCollection(); var commandProcessor = CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(new SubscriberRegistry(), (IAmAHandlerFactory) new ServiceProviderHandlerFactory(container.BuildServiceProvider()))) .Policies(policyRegistry) .NoTaskQueues() .RequestContextFactory(new InMemoryRequestContextFactory()) .Build(); _builder = DispatchBuilder.With() .CommandProcessor(commandProcessor) .MessageMappers(messageMapperRegistry) .DefaultChannelFactory(new ChannelFactory(rmqMessageConsumerFactory)) .Connections(new [] { new RmqSubscription <MyEvent>( new SubscriptionName("foo"), new ChannelName("mary"), new RoutingKey("bob"), timeoutInMilliseconds: 200), new RmqSubscription <MyEvent>( new SubscriptionName("bar"), new ChannelName("alice"), new RoutingKey("simon"), timeoutInMilliseconds: 200) }); }
static void Main(string[] args) { var container = new TinyIoCContainer(); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory) { { typeof(GreetingEvent), typeof(GreetingEventMessageMapper) } }; var messageStore = new InMemoryMessageStore(); var rmqConnnection = new RmqMessagingGatewayConnection { //AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@192.168.99.101:30672/%2f")), Exchange = new Exchange("paramore.brighter.exchange"), }; var producer = new RmqMessageProducer(rmqConnnection); var builder = CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration()) .DefaultPolicy() .TaskQueues(new MessagingConfiguration(messageStore, producer, messageMapperRegistry)) .RequestContextFactory(new InMemoryRequestContextFactory()); var commandProcessor = builder.Build(); Console.WriteLine("Press <ENTER> to stop sending messages"); long loop = 0; while (true) { loop++; if (Console.KeyAvailable) { var key = Console.ReadKey(); if (key.Key == ConsoleKey.Enter) { break; } } Console.WriteLine($"Sending message #{loop}"); commandProcessor.Post(new GreetingEvent($"Ian #{loop}")); if (loop % 100 == 0) { Console.WriteLine("Pausing for breath..."); Task.Delay(4000).Wait(); } } }
public void Establish() { _message = new Message(header: new MessageHeader(Guid.NewGuid(), "nonexistenttopic", MessageType.MT_COMMAND), body: new MessageBody("test content")); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange") }; _messageProducer = new RmqMessageProducer(rmqConnection); }
static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.Console(LogEventLevel.Debug) .CreateLogger(); var container = new Container(); var builder = new ConfigurationBuilder() .AddEnvironmentVariables(); Configuration = builder.Build(); var serviceProvider = ServiceProvider(container, out var messageMapperRegistry, out var handlerConfiguration); var rmqConnnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri(Configuration["RabbitMQ:Uri"])), Exchange = new Exchange(Configuration["RabbitMQ:Exchange"]), }; var commandProcessor = CommandProcessorBuilder.With() .Handlers(handlerConfiguration) .Policies(PolicyRegistry()) .NoTaskQueues() .RequestContextFactory(new InMemoryRequestContextFactory()) .Build(); var dispatcher = DispatchBuilder.With() .CommandProcessor(commandProcessor) .MessageMappers(messageMapperRegistry) .DefaultChannelFactory(new InputChannelFactory(new RmqMessageConsumerFactory(rmqConnnection), new RmqMessageProducerFactory(rmqConnnection))) .Connections(new Connection[] { new Connection <TaskCompletedEvent>( new ConnectionName("TaskCompletedEvent"), new ChannelName("taskcompleted.event"), new RoutingKey("taskcompleted.event"), timeoutInMilliseconds: 200) }).Build(); dispatcher.Receive(); Console.WriteLine("Press <Enter> to exit"); Console.ReadLine(); dispatcher.End().Wait(); commandProcessor.Dispose(); serviceProvider.Dispose(); }
public static void DeclareExchangeForConnection(this IModel channel, RmqMessagingGatewayConnection connection) { if (connection.Exchange.SupportDelay) { channel.ExchangeDeclare(connection.Exchange.Name, "x-delayed-message", connection.Exchange.Durable, autoDelete: false, arguments: new Dictionary <string, object> { { "x-delayed-type", connection.Exchange.Type } }); } else { channel.ExchangeDeclare(connection.Exchange.Name, connection.Exchange.Type, connection.Exchange.Durable); } }
private static IHost BuildHost() { var host = new HostBuilder() .ConfigureLogging(loggingBuilder => loggingBuilder.AddConsole()) .ConfigureHostConfiguration((configurationBuilder) => { configurationBuilder.SetBasePath(Directory.GetCurrentDirectory()); configurationBuilder.AddEnvironmentVariables(prefix: "CCP_"); }) .ConfigureServices((hostContext, services) => { var connections = new Connection[] { new Connection <GuestRoomBookingMade>( new ConnectionName("credit.card.booking.event"), new ChannelName("credit.card.booking.event"), new RoutingKey("booking.event"), timeoutInMilliseconds: 200, isDurable: true, highAvailability: true) }; var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672")), Exchange = new Exchange("hotel.booking.exchange") }; var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqConnection); services.AddServiceActivator(options => { options.Connections = connections; options.ChannelFactory = new ChannelFactory(rmqMessageConsumerFactory); options.BrighterMessaging = new BrighterMessaging(new InMemoryOutbox(), new RmqMessageProducer(rmqConnection)); }).AutoFromAssemblies(); services.AddHostedService <ServiceActivatorHostedService>(); var useLocalAwsServices = hostContext.Configuration.GetValue <bool>("AWS:UseLocalServices"); services.AddDbContext <CardDetailsContext>(options => options.UseMySql(hostContext.Configuration["Database:Bookings"])); }) .UseSerilog() .UseConsoleLifetime() .Build(); return(host); }
public static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var host = new HostBuilder() .ConfigureServices((hostContext, services) => { var subscriptions = new Subscription[] { new RmqSubscription <GreetingEvent>( new SubscriptionName("paramore.example.greeting"), channelName: new ChannelName("greeting.event"), routingKey: new RoutingKey("greeting.event"), bufferSize: 10, timeoutInMilliseconds: 200, isDurable: true, highAvailability: true, makeChannels: OnMissingChannel.Create) }; var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672")), Exchange = new Exchange("paramore.brighter.exchange") }; var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqConnection); var outBox = new InMemoryOutbox(); services.AddServiceActivator(options => { options.Subscriptions = subscriptions; options.ChannelFactory = new ChannelFactory(rmqMessageConsumerFactory); }).AutoFromAssemblies(); services.AddSingleton <IAmAnOutboxViewer <Message> >(outBox); services.AddHostedService <ServiceActivatorHostedService>(); }) .UseConsoleLifetime() .UseSerilog() .Build(); await host.RunAsync(); }
public static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var host = new HostBuilder() .ConfigureServices((hostContext, services) => { var subscriptions = new Subscription[] { new RmqSubscription <GreetingRequest>( new SubscriptionName("paramore.example.greeting"), new ChannelName("Greeting.Request"), new RoutingKey("Greeting.Request"), timeoutInMilliseconds: 200, isDurable: true, highAvailability: true) }; var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672")), Exchange = new Exchange("paramore.brighter.exchange") }; var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqConnection); ChannelFactory amAChannelFactory = new ChannelFactory(rmqMessageConsumerFactory); var producer = new RmqMessageProducer(rmqConnection); services.AddServiceActivator(options => { options.Subscriptions = subscriptions; options.ChannelFactory = amAChannelFactory; }) .UseInMemoryOutbox() .UseExternalBus(producer, true) .AutoFromAssemblies(); services.AddHostedService <ServiceActivatorHostedService>(); }) .UseConsoleLifetime() .UseSerilog() .Build(); await host.RunAsync(); }
public RMQBufferedConsumerTests() { var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange") }; _messageProducer = new RmqMessageProducer(rmqConnection); _messageConsumer = new RmqMessageConsumer(rmqConnection, _topic, _topic, false, false, BatchSize); //create the queue, so that we can receive messages posted to it new QueueFactory(rmqConnection, _topic).Create(3000); }
/// <summary> /// Initializes a new instance of the <see cref="MessageGateway"/> class. /// Use if you need to inject a test logger /// <param name="connection">The amqp uri and exchange to connect to</param> /// </summary> protected MessageGateway(RmqMessagingGatewayConnection connection) { Connection = connection; var connectionPolicyFactory = new ConnectionPolicyFactory(Connection); _retryPolicy = connectionPolicyFactory.RetryPolicy; _circuitBreakerPolicy = connectionPolicyFactory.CircuitBreakerPolicy; _connectionFactory = new ConnectionFactory { Uri = Connection.AmpqUri.Uri.ToString(), RequestedHeartbeat = 30 }; DelaySupported = this is IAmAMessageGatewaySupportingDelay && Connection.Exchange.SupportDelay; }
private static IHost BuildHost() { return(new HostBuilder() .ConfigureLogging(loggingBuilder => loggingBuilder.AddConsole()) .ConfigureHostConfiguration((configurationBuilder) => { configurationBuilder.SetBasePath(Directory.GetCurrentDirectory()); configurationBuilder.AddEnvironmentVariables(prefix: "ASR_"); }) .ConfigureServices((hostContext, services) => { var connections = new Connection[] { new Connection <UpsertAccountEvent>( new ConnectionName("credit.card.account.stream"), new ChannelName("account.event"), new RoutingKey("account.event"), timeoutInMilliseconds: 200, isDurable: true, highAvailability: true) }; var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672")), Exchange = new Exchange("hotel.booking.exchange") }; var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqConnection); services.AddServiceActivator(options => { options.Connections = connections; options.ChannelFactory = new ChannelFactory(rmqMessageConsumerFactory); }) .HandlersFromAssemblies(typeof(UpsertAccountEventHandler).Assembly) .MapperRegistryFromAssemblies(typeof(AccountEventMessageMapper).Assembly); services.AddSingleton <ILoggerFactory>(x => new SerilogLoggerFactory()); services.AddHostedService <ServiceActivatorHostedService>(); services.AddDbContext <CardDetailsContext>(options => options.UseMySql(hostContext.Configuration["Database:CardDetails"])); }) .UseSerilog() .UseConsoleLifetime() .Build()); }
private static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var host = new HostBuilder() .ConfigureServices((hostContext, services) => { var connections = new Connection[] { new Connection <GreetingEvent>( new ConnectionName("paramore.example.greeting"), new ChannelName("greeting.event"), new RoutingKey("greeting.event"), timeoutInMilliseconds: 200, isDurable: true, highAvailability: true) }; var rmqConnnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672")), Exchange = new Exchange("paramore.brighter.exchange") }; var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqConnnection); services.AddServiceActivator(options => { options.Connections = connections; options.ChannelFactory = new InputChannelFactory(rmqMessageConsumerFactory); }) .MapperRegistryFromAssemblies(typeof(GreetingEventHandler).Assembly) .HandlersFromAssemblies(typeof(GreetingEventHandler).Assembly, typeof(ExceptionPolicyHandler <>).Assembly); services.AddSingleton <ILoggerFactory>(x => new SerilogLoggerFactory()); services.AddHostedService <ServiceActivatorHostedService>(); }) .UseConsoleLifetime() .Build(); await host.RunAsync(); }
public TestRMQListener(RmqMessagingGatewayConnection connection, string channelName, params string[] routingKeys) { _channelName = channelName; _connectionFactory = new ConnectionFactory { Uri = connection.AmpqUri.Uri }; _connection = _connectionFactory.CreateConnection(); _channel = _connection.CreateModel(); _channel.DeclareExchangeForConnection(connection); _channel.QueueDeclare(_channelName, false, false, false, null); foreach (var routingKey in routingKeys) { _channel.QueueBind(_channelName, connection.Exchange.Name, routingKey); } }
public RmqMessageProducerSendMessageTests() { _message = new Message(new MessageHeader(Guid.NewGuid(), "test1", MessageType.MT_COMMAND), new MessageBody("test content")); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange") }; _messageProducer = new RmqMessageProducer(rmqConnection); _messageConsumer = new RmqMessageConsumer(rmqConnection, _message.Header.Topic, _message.Header.Topic, false, 1, false); _messageConsumer.Purge(); _client = new TestRMQListener(rmqConnection, _message.Header.Topic); }
/// <summary> /// Initializes a new instance of the <see cref="MessageGateway" /> class. /// </summary> /// <param name="connection"></param> /// <param name="queueName">The queue name.</param> /// <param name="routingKey">The routing key.</param> /// <param name="isDurable">Is the queue persisted to disk</param> /// <param name="preFetchSize">0="Don't send me a new message until I?ve finished", 1= "Send me one message at a time", n = number to grab (take care with competing consumers)</param> /// <param name="highAvailability"></param> public RmqMessageConsumer( RmqMessagingGatewayConnection connection, string queueName, string routingKey, bool isDurable, ushort preFetchSize = 1, bool highAvailability = false) : base(connection) { _queueName = queueName; _routingKey = routingKey; _isDurable = isDurable; _preFetchSize = preFetchSize; IsQueueMirroredAcrossAllNodesInTheCluster = highAvailability; _messageCreator = new RmqMessageCreator(); }
public RmqBrokerNotPreCreatedTests() { _message = new Message( new MessageHeader(Guid.NewGuid(), Guid.NewGuid().ToString(), MessageType.MT_COMMAND), new MessageBody("test content")); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange(Guid.NewGuid().ToString()) }; _messageProducer = new RmqMessageProducer(rmqConnection, new Publication { MakeChannels = OnMissingChannel.Validate }); }
public RmqMessageProducerSendMessageTests() { _message = new Message( new MessageHeader(Guid.NewGuid(), Guid.NewGuid().ToString(), MessageType.MT_COMMAND), new MessageBody("test content")); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange") }; _messageProducer = new RmqMessageProducer(rmqConnection); _messageConsumer = new RmqMessageConsumer(rmqConnection, _message.Header.Topic, _message.Header.Topic, false, false); new QueueFactory(rmqConnection, _message.Header.Topic).Create(3000); }
static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <ILoggerFactory>(new SerilogLoggerFactory()); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672")), Exchange = new Exchange("paramore.brighter.exchange"), }; var producer = new RmqMessageProducer(rmqConnection); var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqConnection); serviceCollection.AddBrighter(options => { var outBox = new InMemoryOutbox(); options.ChannelFactory = new ChannelFactory(rmqMessageConsumerFactory); }) .UseInMemoryOutbox() .UseExternalBus(producer, true) .AutoFromAssemblies(); var serviceProvider = serviceCollection.BuildServiceProvider(); var commandProcessor = serviceProvider.GetService <IAmACommandProcessor>(); Console.WriteLine("Requesting Salutation..."); //blocking call commandProcessor.Call <GreetingRequest, GreetingReply>(new GreetingRequest { Name = "Ian", Language = "en-gb" }, 2000); Console.WriteLine("Done..."); Console.ReadLine(); }
Dispatcher BuildDispatcher(HandlerConfig handlers) { var policy = BuildPolicy(); //create the gateway var rmqConnnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange"), }; //<!-- Events with mapper and handler overrides --> //<add connectionName="Task.ReminderSent" channelName="Task.ReminderSent" routingKey="Task.ReminderSent" dataType="Tasks.Ports.Events.TaskReminderSentEvent" noOfPerformers="1" timeOutInMilliseconds="200" /> //<!-- Generic Events --> //<add connectionName="Task.Added" channelName="Task.Added" routingKey="Task.Added" dataType="GenericListener.Ports.Events.GenericTaskAddedEvent" noOfPerformers="1" timeOutInMilliseconds="200" /> //<add connectionName="Task.Edited" channelName="Task.Edited" routingKey="Task.Edited" dataType="GenericListener.Ports.Events.GenericTaskEditedEvent" noOfPerformers="1" timeOutInMilliseconds="200" /> //<add connectionName="Task.Completed" channelName="Task.Completed" routingKey="Task.Completed" dataType="GenericListener.Ports.Events.GenericTaskCompletedEvent" noOfPerformers="1" timeOutInMilliseconds="200" /> var inputChannelFactory = new InputChannelFactory(new RmqMessageConsumerFactory(rmqConnnection), new RmqMessageProducerFactory(rmqConnnection)); var connections = new List <Connection> { // Events with mapper and handler overrides new Connection(new ConnectionName("Task.ReminderSent"), inputChannelFactory, typeof(Tasks.Ports.Events.TaskReminderSentEvent), new ChannelName("Task.ReminderSent"), "Task.ReminderSent", noOfPerformers: 1, timeoutInMilliseconds: 200), // Generic Events new Connection(new ConnectionName("Task.Added"), inputChannelFactory, typeof(GenericTaskAddedEvent), new ChannelName("Task.Added"), "Task.Added", noOfPerformers: 1, timeoutInMilliseconds: 200), new Connection(new ConnectionName("Task.Edited"), inputChannelFactory, typeof(GenericTaskEditedEvent), new ChannelName("Task.Edited"), "Task.Edited", noOfPerformers: 1, timeoutInMilliseconds: 200), new Connection(new ConnectionName("Task.Completed"), inputChannelFactory, typeof(GenericTaskCompletedEvent), new ChannelName("Task.Completed"), "Task.Completed", noOfPerformers: 1, timeoutInMilliseconds: 200), }; return(DispatchBuilder.With() .CommandProcessor(CommandProcessorBuilder.With() .Handlers(handlers.Handlers) .Policies(policy) .NoTaskQueues() .RequestContextFactory(new InMemoryRequestContextFactory()) .Build()) .MessageMappers(handlers.Mappers) .ChannelFactory(inputChannelFactory) //.ConnectionsFromConfiguration() .Connections(connections) .Build()); }
private static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var host = new HostBuilder() .ConfigureServices((hostContext, services) => { var connections = new Connection[] { new Connection <TaskCreatedEvent>(routingKey: new RoutingKey(nameof(TaskCreatedEvent)), isAsync: true), new Connection <TaskCompletedEvent>(routingKey: new RoutingKey(nameof(TaskCompletedEvent)), isAsync: true) }; var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672")), Exchange = new Exchange("todo.backend.exchange") }; var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqConnection); services.AddServiceActivator(options => { options.Connections = connections; options.ChannelFactory = new ChannelFactory(rmqMessageConsumerFactory); options.BrighterMessaging = new BrighterMessaging(new InMemoryMessageStore(), new RmqMessageProducer(rmqConnection)); }).AutoFromAssemblies(); services.AddHostedService <ServiceActivatorHostedService>(); }) .ConfigureLogging(logging => { logging.ClearProviders(); logging.AddSerilog(dispose: true); }) .UseConsoleLifetime() .Build(); await host.RunAsync(); }
public RmqMessageConsumerOperationInterruptedTests() { var messageHeader = new MessageHeader(Guid.NewGuid(), Guid.NewGuid().ToString(), MessageType.MT_COMMAND); messageHeader.UpdateHandledCount(); _sentMessage = new Message(messageHeader, new MessageBody("test content")); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange") }; _sender = new RmqMessageProducer(rmqConnection); _receiver = new RmqMessageConsumer(rmqConnection, _sentMessage.Header.Topic, _sentMessage.Header.Topic, false, false); _badReceiver = new OperationInterruptedRmqMessageConsumer(rmqConnection, _sentMessage.Header.Topic, _sentMessage.Header.Topic, false, 1, false); _sender.Send(_sentMessage); }
public RmqMessageConsumerMultipleTopicTests() { _messageTopic1 = new Message(new MessageHeader(Guid.NewGuid(), "test1", MessageType.MT_COMMAND), new MessageBody("test content for topic test 1")); _messageTopic2 = new Message(new MessageHeader(Guid.NewGuid(), "test2", MessageType.MT_COMMAND), new MessageBody("test content for topic test 2")); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange") }; var topics = new[] { _messageTopic1.Header.Topic, _messageTopic2.Header.Topic }; _messageProducer = new RmqMessageProducer(rmqConnection); _messageConsumer = new RmqMessageConsumer(rmqConnection, "Multiple.Topic.Queue", topics, false, 1, false); _messageConsumer.Purge(); _client = new TestRMQListener(rmqConnection, "Multiple.Topic.Queue", topics); }
private static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var host = new HostBuilder() .ConfigureServices((hostContext, services) => { var outbox = new InMemoryOutbox(); var gatewayConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange") }; var producer = new RmqMessageProducer( connection: gatewayConnection, new RmqPublication { MakeChannels = OnMissingChannel.Create }); services.AddBrighter() .UseInMemoryOutbox() .UseExternalBus(producer) .AutoFromAssemblies(typeof(GreetingEvent).Assembly); services.AddSingleton <IAmAnOutboxViewer <Message> >(outbox); services.AddHostedService <RunCommandProcessor>(); services.AddHostedService <TimedOutboxSweeper>(); } ) .UseConsoleLifetime() .UseSerilog() .Build(); await host.RunAsync(); }
public void Establish() { var messageHeader = new MessageHeader(Guid.NewGuid(), "test2", MessageType.MT_COMMAND); messageHeader.UpdateHandledCount(); _sentMessage = new Message(header: messageHeader, body: new MessageBody("test content")); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange") }; _sender = new RmqMessageProducer(rmqConnection); _receiver = new RmqMessageConsumer(rmqConnection, _sentMessage.Header.Topic, _sentMessage.Header.Topic, false, 1, false); _badReceiver = new NotSupportedRmqMessageConsumer(rmqConnection, _sentMessage.Header.Topic, _sentMessage.Header.Topic, false, 1, false); _receiver.Purge(); _sender.Send(_sentMessage); }
static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <ILoggerFactory>(new SerilogLoggerFactory()); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672")), Exchange = new Exchange("paramore.brighter.exchange"), }; serviceCollection.AddBrighter() .UseInMemoryOutbox() .UseExternalBus(new RmqProducerRegistryFactory( rmqConnection, new RmqPublication[] { new() { MaxOutStandingMessages = 5, MaxOutStandingCheckIntervalMilliSeconds = 500, WaitForConfirmsTimeOutInMilliseconds = 1000, MakeChannels = OnMissingChannel.Create, Topic = new RoutingKey("greeting.event") }, new() { MaxOutStandingMessages = 5, MaxOutStandingCheckIntervalMilliSeconds = 500, WaitForConfirmsTimeOutInMilliseconds = 1000, MakeChannels = OnMissingChannel.Create, Topic = new RoutingKey("farewell.event") } }).Create())
public RmqMessageProducerDelayedMessageTests() { var header = new MessageHeader(Guid.NewGuid(), Guid.NewGuid().ToString(), MessageType.MT_COMMAND); var originalMessage = new Message(header, new MessageBody("test3 content")); var mutatedHeader = new MessageHeader(header.Id, Guid.NewGuid().ToString(), MessageType.MT_COMMAND); mutatedHeader.Bag.Add(HeaderNames.DELAY_MILLISECONDS, 1000); _message = new Message(mutatedHeader, originalMessage.Body); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.delay.brighter.exchange", supportDelay: true) }; _messageProducer = new RmqMessageProducer(rmqConnection); _messageConsumer = new RmqMessageConsumer(rmqConnection, _message.Header.Topic, _message.Header.Topic, false, false); new QueueFactory(rmqConnection, _message.Header.Topic).Create(3000); }
public RmqMessageProducerDLQTests() { _message = new Message( new MessageHeader(Guid.NewGuid(), Guid.NewGuid().ToString(), MessageType.MT_COMMAND), new MessageBody("test content")); var deadLetterQueueName = $"{_message.Header.Topic}.DLQ"; var deadLetterRoutingKey = $"{_message.Header.Topic}.DLQ"; var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange"), DeadLetterExchange = new Exchange("paramore.brighter.exchange.dlq") }; _messageProducer = new RmqMessageProducer(rmqConnection); _messageConsumer = new RmqMessageConsumer( connection: rmqConnection, queueName: _message.Header.Topic, routingKey: _message.Header.Topic, isDurable: false, highAvailability: false, deadLetterQueueName: deadLetterQueueName, deadLetterRoutingKey: deadLetterRoutingKey, makeChannels: OnMissingChannel.Create ); _deadLetterConsumer = new RmqMessageConsumer( connection: rmqConnection, queueName: deadLetterQueueName, routingKey: deadLetterRoutingKey, isDurable: false, makeChannels: OnMissingChannel.Assume ); //create the infrastructure _messageConsumer.Receive(0); }
public void Establish() { var header = new MessageHeader(Guid.NewGuid(), "test3", MessageType.MT_COMMAND); var originalMessage = new Message(header: header, body: new MessageBody("test3 content")); var mutatedHeader = new MessageHeader(header.Id, "test3", MessageType.MT_COMMAND); mutatedHeader.Bag.Add(HeaderNames.DELAY_MILLISECONDS, 1000); _message = new Message(header: mutatedHeader, body: originalMessage.Body); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange", supportDelay: true) }; _messageProducer = new RmqMessageProducer(rmqConnection); _messageConsumer = new RmqMessageConsumer(rmqConnection, _message.Header.Topic, _message.Header.Topic, false, 1, false); _messageConsumer.Purge(); _client = new TestRMQListener(rmqConnection, _message.Header.Topic); }
static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <ILoggerFactory>(new SerilogLoggerFactory()); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672")), Exchange = new Exchange("paramore.brighter.exchange"), }; var producer = new RmqMessageProducer(rmqConnection, new RmqPublication { MaxOutStandingMessages = 5, MaxOutStandingCheckIntervalMilliSeconds = 500, WaitForConfirmsTimeOutInMilliseconds = 1000, MakeChannels = OnMissingChannel.Create }); serviceCollection.AddBrighter(options => { var outBox = new InMemoryOutbox(); options.BrighterMessaging = new BrighterMessaging(outBox, producer); }).AutoFromAssemblies(); var serviceProvider = serviceCollection.BuildServiceProvider(); var commandProcessor = serviceProvider.GetService <IAmACommandProcessor>(); commandProcessor.Post(new GreetingEvent("Ian says: Hi there!")); commandProcessor.Post(new FarewellEvent("Ian says: See you later!")); }