@@ -29,7 +29,9 @@ groups() ->
29
29
autodelete_amqp091_dest_on_confirm ,
30
30
autodelete_amqp091_dest_on_publish ,
31
31
simple_amqp10_dest ,
32
- simple_amqp10_src
32
+ simple_amqp10_src ,
33
+ message_prop_conversion ,
34
+ message_prop_conversion_no_props
33
35
]},
34
36
{with_map_config , [], [
35
37
simple ,
@@ -168,6 +170,168 @@ simple_amqp10_src(Config) ->
168
170
ok
169
171
end ).
170
172
173
+ message_prop_conversion (Config ) ->
174
+ MapConfig = ? config (map_config , Config ),
175
+ Src = ? config (srcq , Config ),
176
+ Dest = ? config (destq , Config ),
177
+ with_session (Config ,
178
+ fun (Sess ) ->
179
+ shovel_test_utils :set_param (
180
+ Config ,
181
+ <<" test" >>, [{<<" src-protocol" >>, <<" amqp10" >>},
182
+ {<<" src-address" >>, Src },
183
+ {<<" dest-protocol" >>, <<" amqp091" >>},
184
+ {<<" dest-queue" >>, Dest },
185
+ {<<" add-forward-headers" >>, true },
186
+ {<<" dest-add-timestamp-header" >>, true },
187
+ {<<" publish-properties" >>,
188
+ case MapConfig of
189
+ true -> #{<<" cluster_id" >> => <<" x" >>};
190
+ _ -> [{<<" cluster_id" >>, <<" x" >>}]
191
+ end }
192
+ ]),
193
+ LinkName = <<" dynamic-sender-" , Dest /binary >>,
194
+ Tag = <<" tag1" >>,
195
+ Payload = <<" payload" >>,
196
+ {ok , Sender } = amqp10_client :attach_sender_link (Sess , LinkName , Src ,
197
+ unsettled , unsettled_state ),
198
+ ok = await_amqp10_event (link , Sender , attached ),
199
+ Headers = #{durable => true , priority => 3 , ttl => 180000 },
200
+ Msg = amqp10_msg :set_headers (Headers ,
201
+ amqp10_msg :new (Tag , Payload , false )),
202
+ Msg2 = amqp10_msg :set_properties (#{
203
+ message_id => <<" message-id" >>,
204
+ user_id => <<" guest" >>,
205
+ to => <<" to" >>,
206
+ subject => <<" subject" >>,
207
+ reply_to => <<" reply-to" >>,
208
+ correlation_id => <<" correlation-id" >>,
209
+ content_type => <<" content-type" >>,
210
+ content_encoding => <<" content-encoding" >>,
211
+ % absolute_expiry_time => 123456789,
212
+ creation_time => 123456789 ,
213
+ group_id => <<" group-id" >>,
214
+ group_sequence => 123 ,
215
+ reply_to_group_id => <<" reply-to-group-id" >>
216
+ }, Msg ),
217
+ Msg3 = amqp10_msg :set_application_properties (#{
218
+ <<" x-binary" >> => <<" binary" >>,
219
+ <<" x-int" >> => 33 ,
220
+ <<" x-negative-int" >> => - 33 ,
221
+ <<" x-float" >> => 1.3 ,
222
+ <<" x-true" >> => true ,
223
+ <<" x-false" >> => false
224
+ }, Msg2 ),
225
+ ok = amqp10_client :send_msg (Sender , Msg3 ),
226
+ receive
227
+ {amqp10_disposition , {accepted , Tag }} -> ok
228
+ after 3000 ->
229
+ exit (publish_disposition_not_received )
230
+ end ,
231
+ amqp10_client :detach_link (Sender ),
232
+ Channel = rabbit_ct_client_helpers :open_channel (Config ),
233
+ {# 'basic.get_ok' {}, # amqp_msg {payload = Payload , props = # 'P_basic' {
234
+ content_type = ReceivedContentType ,
235
+ content_encoding = ReceivedContentEncoding ,
236
+ headers = Headers2 ,
237
+ delivery_mode = ReceivedDeliveryMode ,
238
+ priority = ReceivedPriority ,
239
+ correlation_id = ReceivedCorrelationId ,
240
+ reply_to = ReceivedReplyTo ,
241
+ expiration = ReceivedExpiration ,
242
+ message_id = ReceivedMessageId ,
243
+ timestamp = ReceivedTimestamp ,
244
+ type = _ReceivedType ,
245
+ user_id = ReceivedUserId ,
246
+ app_id = _ReceivedAppId ,
247
+ cluster_id = _ReceivedClusterId
248
+ }}} = amqp_channel :call (Channel , # 'basic.get' {queue = Dest , no_ack = true }),
249
+
250
+ ? assertEqual (<<" payload" >>, Payload ),
251
+ ? assertEqual (2 , ReceivedDeliveryMode ),
252
+ ? assertEqual ({longstr , <<" binary" >>}, rabbit_misc :table_lookup (Headers2 , <<" x-binary" >>)),
253
+ ? assertEqual ({long , 33 }, rabbit_misc :table_lookup (Headers2 , <<" x-int" >>)),
254
+ ? assertEqual ({long , - 33 }, rabbit_misc :table_lookup (Headers2 , <<" x-negative-int" >>)),
255
+ ? assertEqual ({double , 1.3 }, rabbit_misc :table_lookup (Headers2 , <<" x-float" >>)),
256
+ ? assertEqual ({bool , true }, rabbit_misc :table_lookup (Headers2 , <<" x-true" >>)),
257
+ ? assertEqual ({bool , false }, rabbit_misc :table_lookup (Headers2 , <<" x-false" >>)),
258
+
259
+ ? assertEqual (<<" content-type" >>, ReceivedContentType ),
260
+ ? assertEqual (<<" content-encoding" >>, ReceivedContentEncoding ),
261
+
262
+ ? assertEqual (3 , ReceivedPriority ),
263
+ ? assertEqual (<<" correlation-id" >>, ReceivedCorrelationId ),
264
+ ? assertEqual (<<" reply-to" >>, ReceivedReplyTo ),
265
+ ? assertEqual (<<" 180000" >>, ReceivedExpiration ),
266
+ ? assertEqual (<<" message-id" >>, ReceivedMessageId ),
267
+ ? assertEqual (123456 , ReceivedTimestamp ), % timestamp is divided by 1 000
268
+ ? assertEqual (<<" guest" >>, ReceivedUserId ),
269
+ ok
270
+ end ).
271
+
272
+ message_prop_conversion_no_props (Config ) ->
273
+ MapConfig = ? config (map_config , Config ),
274
+ Src = ? config (srcq , Config ),
275
+ Dest = ? config (destq , Config ),
276
+ with_session (Config ,
277
+ fun (Sess ) ->
278
+ shovel_test_utils :set_param (
279
+ Config ,
280
+ <<" test" >>, [{<<" src-protocol" >>, <<" amqp10" >>},
281
+ {<<" src-address" >>, Src },
282
+ {<<" dest-protocol" >>, <<" amqp091" >>},
283
+ {<<" dest-queue" >>, Dest },
284
+ {<<" add-forward-headers" >>, true },
285
+ {<<" dest-add-timestamp-header" >>, true },
286
+ {<<" publish-properties" >>,
287
+ case MapConfig of
288
+ true -> #{<<" cluster_id" >> => <<" x" >>};
289
+ _ -> [{<<" cluster_id" >>, <<" x" >>}]
290
+ end }
291
+ ]),
292
+ LinkName = <<" dynamic-sender-" , Dest /binary >>,
293
+ Tag = <<" tag1" >>,
294
+ Payload = <<" payload" >>,
295
+ {ok , Sender } = amqp10_client :attach_sender_link (Sess , LinkName , Src ,
296
+ unsettled , unsettled_state ),
297
+ ok = await_amqp10_event (link , Sender , attached ),
298
+ Msg = amqp10_msg :new (Tag , Payload , false ),
299
+ ok = amqp10_client :send_msg (Sender , Msg ),
300
+ receive
301
+ {amqp10_disposition , {accepted , Tag }} -> ok
302
+ after 3000 ->
303
+ exit (publish_disposition_not_received )
304
+ end ,
305
+ amqp10_client :detach_link (Sender ),
306
+ Channel = rabbit_ct_client_helpers :open_channel (Config ),
307
+ {# 'basic.get_ok' {}, # amqp_msg {payload = ReceivedPayload , props = # 'P_basic' {
308
+ content_type = undefined ,
309
+ content_encoding = undefined ,
310
+ headers = ReceivedHeaders ,
311
+ delivery_mode = ReceivedDeliveryMode ,
312
+ priority = ReceivedPriority ,
313
+ correlation_id = undefined ,
314
+ reply_to = undefined ,
315
+ expiration = undefined ,
316
+ message_id = undefined ,
317
+ timestamp = undefined ,
318
+ type = undefined ,
319
+ user_id = undefined ,
320
+ app_id = undefined ,
321
+ cluster_id = ReceivedClusterId
322
+ }}} = amqp_channel :call (Channel , # 'basic.get' {queue = Dest , no_ack = true }),
323
+
324
+ ? assertEqual (<<" payload" >>, ReceivedPayload ),
325
+ ? assertEqual (1 , ReceivedDeliveryMode ),
326
+ ? assertEqual (<<" x" >>, ReceivedClusterId ),
327
+ ? assertEqual (4 , ReceivedPriority ),
328
+
329
+ ? assertNotEqual (undefined , rabbit_misc :table_lookup (ReceivedHeaders , <<" x-shovelled" >>)),
330
+
331
+ ok
332
+ end ).
333
+
334
+
171
335
change_definition (Config ) ->
172
336
Src = ? config (srcq , Config ),
173
337
Dest = ? config (destq , Config ),
0 commit comments