public async Task RabbitMQClientBus_PublishEventAsync_Should_Be_Readable() { var appId = Guid.NewGuid(); const string queueName = "test_publish_queue_1"; try { _channel.ExchangeDeclare( exchange: appId + "_events", type: ExchangeType.Fanout, durable: true, autoDelete: false); _channel.QueueDeclare(queueName, false, true, true); _channel.QueueBind(queueName, appId + "_events", ""); var evt = new RabbitEvent { Data = "testData" }; var b = new RabbitMQEventBus( new JsonDispatcherSerializer(), new RabbitMQClientBusConfiguration(appId.ToString(), _testConfiguration["host"], _testConfiguration["user"], _testConfiguration["password"])); var allCalled = false; await b.PublishEventAsync(evt).ContinueWith(t => { t.Result.IsSuccess.Should().BeTrue(); var result = _channel.BasicGet(queueName, true); result.Should().NotBeNull(); var enveloppeAsStr = Encoding.UTF8.GetString(result.Body); enveloppeAsStr.Should().NotBeNullOrWhiteSpace(); var receivedEnveloppe = enveloppeAsStr.FromJson <Enveloppe>(); receivedEnveloppe.Should().NotBeNull(); var type = Type.GetType(receivedEnveloppe.AssemblyQualifiedDataType); var evet = receivedEnveloppe.Data.FromJson(type); evet.Should().BeOfType <RabbitEvent>(); evet.As <RabbitEvent>().Data.Should().Be("testData"); allCalled = true; }).ConfigureAwait(false); allCalled.Should().BeTrue(); } finally { _channel.ExchangeDelete(appId + "_events"); _channel.QueueDelete(queueName); } }
[Benchmark] // We add those benchmark that are mainly the same as command cause we must not see any perf differences between these two public async Task DispatchEvent() { var bus = new RabbitMQEventBus(new JsonDispatcherSerializer(), new RabbitPublisherBusConfiguration("benchmark", "localhost", "guest", "guest")); await bus.PublishEventAsync(new TestDispatchEvent(0, false, 0)); }