public async Task Publish_an_event() { var hybridConnectionSetting = await GetHybridConnectionSetting(); var eventGridSetting = await GetEventGridSetting(); var hybridConnectionListenerHelper = new HybridConnectionListenerHelper(hybridConnectionSetting); hybridConnectionListenerHelper.Start(); var moqLogger = new Mock <ILogger <EventPublisher> >(); var eventBus = new EventPublisher(eventGridSetting, moqLogger.Object); var orderCheckoutEvent = new OrderCheckoutEvent { OrderId = Guid.NewGuid() }; await eventBus.Publish("ordercheckout", "Order Checkout", orderCheckoutEvent); var eventMessages = await hybridConnectionListenerHelper.GetReceivedEvent("ordercheckout"); Assert.Single(eventMessages); var receivedEvent = GetEventData(eventMessages); Assert.Equal(orderCheckoutEvent.OrderId, receivedEvent.OrderId); await hybridConnectionListenerHelper.Stop(); }
public void PublishOrderCheckout(string queueName, OrderCheckoutEvent orderModel) { using (var channel = _connection.CreateModel()) { channel.QueueDeclare(queueName, false, false, false, null); var message = JsonConvert.SerializeObject(orderModel); var body = Encoding.UTF8.GetBytes(message); IBasicProperties properties = channel.CreateBasicProperties(); properties.Persistent = true; properties.DeliveryMode = 2; channel.ConfirmSelect(); channel.BasicPublish("", queueName, properties, body); channel.WaitForConfirmsOrDie(); channel.BasicAcks += (sender, eventArg) => { Console.WriteLine("send RabbitMq"); }; channel.ConfirmSelect(); } }