public void ConfigureRabbitListeners(IRabbitListenerEndpointRegistrar registrar) { var listener = new MyMessageListener(loggerFactory.CreateLogger <MyMessageListener>()); SimpleRabbitListenerEndpoint endpoint = new SimpleRabbitListenerEndpoint(context, listener); endpoint.Id = "manual-endpoint"; endpoint.SetQueueNames("myqueue"); registrar.RegisterEndpoint(endpoint); }
public static IHostBuilder CreatHostBuilder(string[] args) => RabbitMQHost.CreateDefaultBuilder(args) .ConfigureServices((hostBuilderContext, services) => { // Add queue to be declared services.AddRabbitQueue(new Queue("myqueue")); services.AddRabbitDirecListenerContainer((p) => { var context = p.GetRequiredService <IApplicationContext>(); var factory = p.GetRequiredService <IRabbitListenerContainerFactory>(); var logFactory = p.GetRequiredService <ILoggerFactory>(); var listener = new MyMessageListener(logFactory.CreateLogger <MyMessageListener>()); var endpoint = new SimpleRabbitListenerEndpoint(context); endpoint.SetQueueNames("myqueue"); endpoint.MessageListener = listener; var container = factory.CreateListenerContainer(endpoint) as DirectMessageListenerContainer; container.ServiceName = "manualContainer"; return(container); }); // Add a message sender services.AddSingleton <IHostedService, MyRabbitSender>(); });