@@ -20,6 +20,7 @@ public class RabbitMqSubscriber : IXCSubscriber
2020 private readonly string _privateCommunicationIdentifier ;
2121 private readonly ISerializer _serializer ;
2222 private readonly string _component ;
23+ private SerializationType _serializationType ;
2324
2425 private readonly ConcurrentDictionary < SubscriptionKey , RabbitMqSubscriberInfos > _subscribersDico ;
2526 private readonly ConcurrentDictionary < StreamSubscriptionKey , IDisposable > _streamSubscriptionsDico ;
@@ -36,6 +37,7 @@ public RabbitMqSubscriber(string component, IXCConfiguration xcConfiguration, IC
3637 _streamSubscriptionsDico = new ConcurrentDictionary < StreamSubscriptionKey , IDisposable > ( ) ;
3738 _privateCommunicationIdentifier = privateCommunicationIdentifier ;
3839 _serializer = serializer ;
40+ InitSerializationType ( ) ;
3941 InitObservableCollection ( ) ;
4042 }
4143
@@ -129,8 +131,8 @@ private void InitSubscriber(string stateMachine, string privateCommunicationIden
129131 bool createExchangeChannel = false ;
130132 RabbitMqSubscriberInfos rabbitMqSubscriberInfos = null ;
131133
132- EventHandler < BasicDeliverEventArgs > handler = ( o , basicAckEventArgs ) =>
133- {
134+ EventHandler < BasicDeliverEventArgs > handler = ( o , basicAckEventArgs ) =>
135+ {
134136 var stateMachineRefHeader = RabbitMqHeaderConverter . ConvertStateMachineRefHeader ( basicAckEventArgs . BasicProperties . Headers ) ;
135137
136138 if ( stateMachineRefHeader . StateMachineCode == stateMachineCode )
@@ -139,9 +141,9 @@ private void InitSubscriber(string stateMachine, string privateCommunicationIden
139141
140142 var obj = _serializer . Deserialize ( new MemoryStream ( basicAckEventArgs . Body ) ) ;
141143
142- var msgEventArgs = new MessageEventArgs ( stateMachineRefHeader , obj ) ;
144+ var msgEventArgs = new MessageEventArgs ( stateMachineRefHeader , obj , _serializationType ) ;
143145
144- OnMessageReceived ( msgEventArgs ) ;
146+ OnMessageReceived ( msgEventArgs ) ;
145147 }
146148 } ;
147149
@@ -184,7 +186,7 @@ private void InitSubscriber(string stateMachine, string privateCommunicationIden
184186 {
185187 // Update the existing subscription for that routing key to subscribe the new handler..
186188 rabbitMqSubscriberInfos . AddHandler ( handler ) ;
187- }
189+ }
188190 }
189191 }
190192 catch ( OperationInterruptedException e )
@@ -193,6 +195,26 @@ private void InitSubscriber(string stateMachine, string privateCommunicationIden
193195 }
194196 }
195197
198+ private void InitSerializationType ( )
199+ {
200+ var serialization = _xcConfiguration . GetSerializationType ( ) ;
201+
202+ switch ( serialization )
203+ {
204+ case XCApiTags . Binary :
205+ _serializationType = SerializationType . Binary ;
206+ break ;
207+ case XCApiTags . Json :
208+ _serializationType = SerializationType . Json ;
209+ break ;
210+ case XCApiTags . Bson :
211+ _serializationType = SerializationType . Bson ;
212+ break ;
213+ default :
214+ throw new XCSerializationException ( "Serialization type not supported" ) ;
215+ }
216+ }
217+
196218 private void CreateExchangeChannel ( string exchangeName , string routingKey , out IModel channel , out EventingBasicConsumer subscriber )
197219 {
198220 if ( _connection == null || ! _connection . IsOpen )
0 commit comments