static async Task SimplePoolTestAsync() { var configManager = CreateConfigurationManager(); var consumerFactory = new RMQConsumerFactory(new RMQConnectionFactory()); var producerFactory = new RMQProducerFactory(new RMQConnectionFactory()); var subscriberFactory = new RMQSubscriberFactory(new RMQConnectionFactory()); var publisherFactory = new RMQPublisherFactory(new RMQConnectionFactory()); var factory = new RMQSenderReceiverFactory(consumerFactory, producerFactory, subscriberFactory, publisherFactory); using (var amqPool = new RMQPoolAsync(configManager, factory, 5)) { using (var producer = await amqPool.GetAsync <IRMQProducerText>("connection", "MY_RMQ_TEST")) { await producer.Instance.SendAsync("Simple test"); } } }
static Task PoolTestAsync() { var configManager = CreateConfigurationManager(); var consumerFactory = new RMQConsumerFactory(new RMQConnectionFactory()); var producerFactory = new RMQProducerFactory(new RMQConnectionFactory()); var subscriberFactory = new RMQSubscriberFactory(new RMQConnectionFactory()); var publisherFactory = new RMQPublisherFactory(new RMQConnectionFactory()); var factory = new RMQSenderReceiverFactory(consumerFactory, producerFactory, subscriberFactory, publisherFactory); using (var amqPool = new RMQPoolAsync(configManager, factory, 5)) { var tasks = new List <Task>(); for (var i = 0; i < 10; i++) { var task = Task.Run(async() => { try { for (var j = 0; j < 10; j++) { using (var producer = await amqPool.GetAsync <IRMQProducerText>("connection", "MY_RMQ_TEST")) { var message = $"message: {i * j}"; await producer.Instance.SendAsync(message); Console.WriteLine($"Thread: {Thread.CurrentThread.ManagedThreadId} - {producer.PoolId} - {producer.Instance.Id} - {message}"); } } } catch (Exception ex) { Console.WriteLine(ex); } }); tasks.Add(task); } Console.WriteLine("Waiting for Tasks to complete..."); Task.WaitAll(tasks.ToArray()); Console.WriteLine("Tasks completed."); return(Task.CompletedTask); } }
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); }