@@ -15,7 +15,7 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
1515{
1616 public class EventBusRabbitMQ : IEventBus
1717 {
18- private readonly string _brokerName = "event_bus " ;
18+ private readonly string _brokerName = "eshop_event_bus " ;
1919 private readonly string _connectionString ;
2020 private readonly Dictionary < string , List < IIntegrationEventHandler > > _handlers ;
2121 private readonly List < Type > _eventTypes ;
@@ -120,24 +120,11 @@ private IModel GetChannel()
120120
121121 var consumer = new EventingBasicConsumer ( channel ) ;
122122 consumer . Received += async ( model , ea ) =>
123- {
123+ {
124124 var eventName = ea . RoutingKey ;
125- if ( _handlers . ContainsKey ( eventName ) )
126- {
127- var message = Encoding . UTF8 . GetString ( ea . Body ) ;
128- Type eventType = _eventTypes . Single ( t => t . Name == eventName ) ;
129-
130- var integrationEvent = JsonConvert . DeserializeObject ( message , eventType ) ;
131- var handlers = _handlers [ eventName ] ;
132-
133-
134- var concreteType = typeof ( IIntegrationEventHandler < > ) . MakeGenericType ( eventType ) ;
135-
136- foreach ( var handler in handlers )
137- {
138- await ( Task ) concreteType . GetMethod ( "Handle" ) . Invoke ( handler , new object [ ] { integrationEvent } ) ;
139- }
140- }
125+ var message = Encoding . UTF8 . GetString ( ea . Body ) ;
126+
127+ await ProcessEvent ( eventName , message ) ;
141128 } ;
142129 channel . BasicConsume ( queue : _queueName ,
143130 noAck : true ,
@@ -147,5 +134,21 @@ private IModel GetChannel()
147134 return _connection . Item1 ;
148135 }
149136 }
137+
138+ private async Task ProcessEvent ( string eventName , string message )
139+ {
140+ if ( _handlers . ContainsKey ( eventName ) )
141+ {
142+ Type eventType = _eventTypes . Single ( t => t . Name == eventName ) ;
143+ var integrationEvent = JsonConvert . DeserializeObject ( message , eventType ) ;
144+ var concreteType = typeof ( IIntegrationEventHandler < > ) . MakeGenericType ( eventType ) ;
145+ var handlers = _handlers [ eventName ] ;
146+
147+ foreach ( var handler in handlers )
148+ {
149+ await ( Task ) concreteType . GetMethod ( "Handle" ) . Invoke ( handler , new object [ ] { integrationEvent } ) ;
150+ }
151+ }
152+ }
150153 }
151154}
0 commit comments