public void ConfigureServices(IServiceCollection services) { var configManager = new RMQConfigurationManager(); var connectionSettings = configManager.GetConnectionSettings("connection"); var exchangeSettings = configManager.GetExchangeSettings("my_rmq_test_exchange"); var queueSettings = configManager.GetQueueSettings("my_rmq_test"); services.AddRMQBoundConsumer <TestBoundConsumerText>(options => { options.ConnectionSettings = connectionSettings; options.QueueSettings = queueSettings; }); //services.AddRMQBoundSubscriber<TestBoundConsumerText>(options => //{ // options.ConnectionSettings = connectionSettings; // options.ExchangeSettings = exchangeSettings; // options.QueueSettings = queueSettings; //}); services.AddControllers(); }
static public async Task RunAsync() { var configuration = new RMQConfigurationManager($"{AppDomain.CurrentDomain.BaseDirectory}RMQSettings.Issue.json"); var connectionFactory = new RMQConnectionFactory(); var consumerFactory = new RMQConsumerFactory(connectionFactory); var producerFactory = new RMQProducerFactory(connectionFactory); var subscriberFactory = new RMQSubscriberFactory(connectionFactory); var publisherFactory = new RMQPublisherFactory(connectionFactory); var factory = new RMQSenderReceiverFactory(consumerFactory, producerFactory, subscriberFactory, publisherFactory); var pool = new RMQPoolAsync(configuration, factory, 10); var result = (RMQReceiverResultText)null; var queueDetails = configuration.GetQueueSettings("Engine.Inbound"); using (var container = await pool.GetAsync <IRMQConsumerText>("connection", queueDetails.Name)) { var reader = container.Instance; reader.Mode = ConsumerMode.OnNoMessage_ReturnNull; try { result = reader.Receive(1000); if (result != null) { } } catch (TimeoutException) { // no data, just return null as an indicator } catch (MessageException ex) { switch (ex.ExceptionCode) { case MessageExceptionCode.ExclusiveLock: await Task.Delay(1000); break; case MessageExceptionCode.LostConnection: await Task.Delay(1000); reader.ClearCacheBuffer(); throw; default: reader.ClearCacheBuffer(); throw; } } catch (Exception) { result?.Reject(); throw; } } //var qs = configManager.GetQueueSettings("Ross"); // await PublisherAsync("Ross", "Red"); // await ProducerPerformanceTestAsync(); // await ProducerAsync(); // await ConsumerAsync(); // await PoolTestAsync(); // await SimplePoolTestAsync(); // await PoolAsyncManagerReadTestAsync(); //var rmqConnectionSetting = new RMQConnectionSettings //{ // Name = "connection", // Username = "******", // Password = "******", // VirtualHost = "/", // DelayOnReconnect = 1500, // Uri = "amqp://some-host:5672" //}; //var queues = new List<RMQQueueSettings>(); //foreach (var queue in new[] { "Engine.Inbound","Engine.Outbound","ERROR.SparkEvents" }) //{ // queues.Add(new RMQQueueSettings(queue, queue, true, false, false, true)); //} //var config = new RMQConfigurationManager(new[] { rmqConnectionSetting }, queueSettings: queues); //var con = config.GetConnectionSettings("connection"); //var queuesetting = config.GetQueueSettings("lms.activity.items"); await Task.Delay(0); }