What do you mean by it doesn&#39;t segfault with�rabbitmq-c-fb6fca832fd2 ? �Did you build Net::RabbitMQ with that version of rabbitmq-c and it ran the script below without crashing?<div><br></div><div>-Alan<br><div><div><br>
<div class="gmail_quote">On Wed, Apr 4, 2012 at 3:12 AM, Matti Linnanvuori <span dir="ltr">&lt;<a href="mailto:matti.linnanvuori@portalify.com">matti.linnanvuori@portalify.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi!<br>
<br>
I wonder how it is possible to have recv hang if RabbitMQ server has disconnected. Maybe RabbitMQ server has a bug that it does not disconnect a socket.<br>
<br>
I am afraid I don&#39;t have a succinct example that can reproduce this segfault. It occurred with Net::RabbitMQ versions 0.2.0 and 0.2.2, but not with rabbitmq-c-fb6fca832fd2.<br>
<br>
I reported the segmentation fault in CPAN:<br>
<a href="https://rt.cpan.org/Public/Bug/Display.html?id=76205" target="_blank">https://rt.cpan.org/Public/Bug/Display.html?id=76205</a><br>
<br>
I got the segmentation fault in subroutine get. I think it is because memory allocation failed.<br>
I have Net::RabbitMQ version 0.2.2. I got a similar bug in Net::RabbitMQ version 0.2.0, too:<a href="https://rt.cpan.org/Public/Bug/Display.html?id=76156" target="_blank">https://rt.cpan.org/Public/Bug/Display.html?id=76156</a><br>

This is perl, v5.10.0 built for x86_64-linux-thread-multi<br>
Linux pmc-inst-test 2.6.32.12-0.7-default #1 SMP 2010-05-20 11:14:20 +0200 x86_64 x86_64 x86_64 GNU/Linux<br>
<br>
Program received signal SIGSEGV, Segmentation fault.<br>
0x00007ffff724fa41 in memcpy () from /lib64/libc.so.6<br>
(gdb) bt<br>
#0 0x00007ffff724fa41 in memcpy () from /lib64/libc.so.6<br>
#1 0x00007ffff6db2c0d in amqp_handle_input (state=0x7bc8a0,<br>
received_data=..., decoded_frame=0x7fffffffe2c0)<br>
at /usr/include/bits/string3.h:52<br>
#2 0x00007ffff6dbbeec in wait_frame_inner (state=0x7bc8a0,<br>
decoded_frame=0x7fffffffe2c0) at amqp_socket.c:167<br>
#3 0x00007ffff6dbc489 in amqp_simple_rpc (state=0x7bc8a0, channel=3,<br>
request_id=, expected_reply_ids=0x7fffffffe3a0,<br>
decoded_request_method=) at amqp_socket.c:283<br>
#4 0x00007ffff6db156c in amqp_basic_get (state=0x7bc8a0, channel=7,<br>
queue=..., no_ack=1) at amqp_api.c:258<br>
#5 0x00007ffff6da7432 in XS_Net__RabbitMQ_get (my_perl=,<br>
cv=) at RabbitMQ.xs:618<br>
#6 0x000000000047e115 in Perl_pp_entersub ()<br>
#7 0x0000000000455ad3 in Perl_runops_debug ()<br>
#8 0x000000000047a005 in perl_run ()<br>
#9 0x000000000042172c in main ()<br>
(gdb)<br>
<br>
#!/usr/bin/perl -w<br>
<br>
=pod<br>
<br>
=head1 sds2sds_sf_fault.t<br>
<br>
�Test 1: publish a Dispatch JSON message with ack_level and valid_until<br>
�- from SDS to SDS in exchange.pmc.router-in.<br>
�Try to receive a message from exchange.pmc.router-in in 8 seconds.<br>
�Test 1 expected result: a message is received from exchange.pmc.router-in in 8 seconds.<br>
�Test 2: decode the message as JSON.<br>
�Test 2 expected result: the message is decoded as JSON.<br>
�Test 3: check that the sender field is the same as in the sent message.<br>
�Test 3 expected result: the sender field is the same as in the sent message.<br>
�Test 4: check the body of the received message and the sent one.<br>
�Test 4 expected result: the body fields are the same.<br>
�Test 5: check the timestamp field.<br>
�Test 5 expected result: the timestamp field is the same as in the published message.<br>
�Test 6: try to receive a message from exchange.pmc.sf-in in 8 seconds.<br>
�Test 6 expected result: a message is received from exchange.pmc.sf-in in 8 seconds.<br>
�Test 7: decode the message as JSON.<br>
�Test 7 expected result: the message is decoded as JSON.<br>
�Test 8: check that the sender field is &quot;exchange.pmc.router-in&quot;.<br>
�Test 8 expected result: the sender field is &quot;exchange.pmc.router-in&quot;.<br>
�Test 9: check the body of the received message and the sent one.<br>
�Test 9 expected result: the body fields are the same.<br>
�Test 10: check that the timestamp in an integer.<br>
�Test 10 expected result: the timestamp in an integer.<br>
�Test 11: check that the timestamp is greater than or equal to that of before publishing.<br>
�Test 11 expected result: the timestamp is greater than or equal to that of before publishing.<br>
�Test 12: check that the timestamp is less than or equal to that of now.<br>
�Test 12 expected result: the timestamp is less than or equal to that of now.<br>
�Test 13: try to receive a message from exchange.pmc.router-in in 8 seconds.<br>
�Test 13 expected result: a message is received from exchange.pmc.router-in in 8 seconds.<br>
�Test 14: decode the message as JSON.<br>
�Test 14 expected result: the message is decoded as JSON.<br>
�Test 15: check that the sender field is &quot;exchange.pmc.sf-in&quot;.<br>
�Test 15 expected result: the sender field is &quot;exchange.pmc.sf-in&quot;.<br>
�Test 16: check the body of the received message and the sent one.<br>
�Test 16 expected result: the body fields are the same.<br>
�Test 17: check that the timestamp in an integer.<br>
�Test 17 expected result: the timestamp in an integer.<br>
�Test 18: check that the timestamp is greater than or equal to that of before publishing.<br>
�Test 18 expected result: the timestamp is greater than or equal to that of before publishing.<br>
�Test 19: check that the timestamp is less than or equal to that of now.<br>
�Test 19 expected result: the timestamp is less than or equal to that of now.<br>
�Test 20: try to receive a message from exchange.pmc.router-in in 8 seconds.<br>
�Test 20 expected result: a message is received from exchange.pmc.router-in in 8 seconds.<br>
�Test 21: decode the message as JSON.<br>
�Test 21 expected result: the message is decoded as JSON.<br>
�Test 22: check that the sender field is &quot;exchange.pmc.sf-in&quot;.<br>
�Test 22 expected result: the sender field is &quot;exchange.pmc.sf-in&quot;.<br>
�Test 23: check that the timestamp in an integer.<br>
�Test 23 expected result: the timestamp in an integer.<br>
�Test 24: check that the timestamp is greater than or equal to that of before publishing.<br>
�Test 24 expected result: the timestamp is greater than or equal to that of before publishing.<br>
�Test 25: check that the timestamp is less than or equal to that of now.<br>
�Test 25 expected result: the timestamp is less than or equal to that of now.<br>
�Test 26: check that the id fields of the received and the published messages are the same.<br>
�Test 26 expected result: the id fields of the received and the published messages are the same.<br>
�Test 27: check that the ack_type field has value &quot;processed&quot;.<br>
�Test 27 expected result: the ack_type field has value &quot;processed&quot;.<br>
�Test 28: check that the from field of the received message is the same as<br>
�the to field of the published message.<br>
�Test 28 expected result: the from field of the received message is the same as<br>
�the to field of the published message.<br>
�Test 29: check that the type field has value &quot;ack&quot;.<br>
�Test 29 expected result: the type field has value &quot;ack&quot;.<br>
�Test 30: check that the version field has value 1.<br>
�Test 30 expected result: the version field has value 1.<br>
�Test 31: try to receive a message from exchange.pmc.cassidian-in in 8 seconds.<br>
�Test 31 expected result: a message is received from exchange.pmc.cassidian-in in 8 seconds.<br>
�Test 32: decode the message as JSON.<br>
�Test 32 expected result: the message is decoded as JSON.<br>
�Test 33: check that the sender field is &quot;exchange.pmc.router-in&quot;.<br>
�Test 33 expected result: the sender field is &quot;exchange.pmc.router-in&quot;.<br>
�Test 34: check the body of the received message and the sent one.<br>
�Test 34 expected result: the body fields are the same.<br>
�Test 35: check that the timestamp in an integer.<br>
�Test 35 expected result: the timestamp in an integer.<br>
�Test 36: check that the timestamp is greater than or equal to that of before publishing.<br>
�Test 36 expected result: the timestamp is greater than or equal to that of before publishing.<br>
�Test 37: check that the timestamp is less than or equal to that of now.<br>
�Test 37 expected result: the timestamp is less than or equal to that of now.<br>
�Test 38: try to receive a message from exchange.pmc.cassidian-in in 8 seconds.<br>
�Test 38 expected result: a message is received from exchange.pmc.cassidian-in in 8 seconds.<br>
�Test 39: decode the message as JSON.<br>
�Test 39 expected result: the message is decoded as JSON.<br>
�Test 40: check that the sender field is &quot;exchange.pmc.router-in&quot;.<br>
�Test 40 expected result: the sender field is &quot;exchange.pmc.router-in&quot;.<br>
�Test 41: check that the timestamp in an integer.<br>
�Test 41 expected result: the timestamp in an integer.<br>
�Test 42: check that the timestamp is greater than or equal to that of before publishing.<br>
�Test 42 expected result: the timestamp is greater than or equal to that of before publishing.<br>
�Test 43: check that the timestamp is less than or equal to that of now.<br>
�Test 43 expected result: the timestamp is less than or equal to that of now.<br>
�Test 44: check that the id fields of the received and the published messages are the same.<br>
�Test 44 expected result: the id fields of the received and the published messages are the same.<br>
�Test 45: check that the ack_type field has value &quot;processed&quot;.<br>
�Test 45 expected result: the ack_type field has value &quot;processed&quot;.<br>
�Test 46: check that the from field of the received message is the same as<br>
�the to field of the published message.<br>
�Test 46 expected result: the from field of the received message is the same as<br>
�the to field of the published message.<br>
�Test 47: check that the type field has value &quot;ack&quot;.<br>
�Test 47 expected result: the type field has value &quot;ack&quot;.<br>
�Test 48: check that the version field has value 1.<br>
�Test 48 expected result: the version field has value 1.<br>
�Test 49: publish an Ack sent message from the SSI in exchange.pmc.router-in.<br>
�try to receive a message from exchange.pmc.router-in in 8 seconds.<br>
�Test 49 expected result: a message is received from exchange.pmc.router-in in 8 seconds.<br>
�Test 50: decode the message as JSON.<br>
�Test 50 expected result: the message is decoded as JSON.<br>
�Test 51: check that the timestamp of the received message is the same as that of published one.<br>
�Test 51 expected result:<br>
�the timestamp of the received message is the same as that of published one.<br>
�Test 52: check the sender field of the received message.<br>
�Test 52 expected result:<br>
�the sender field of the received message has value &quot;exchange.pmc.cassidian-in&quot;.<br>
�Test 53: check the body fields of the received and the published messages.<br>
�Test 53 expected result:<br>
�the body fields of the received and the published messages are the same.<br>
�Test 54: try to receive a message from exchange.pmc.sf-in in 8 seconds.<br>
�Test 54 expected result: a message is received from exchange.pmc.sf-in in 8 seconds.<br>
�Test 55: decode the message as JSON.<br>
�Test 55 expected result: the message is decoded as JSON.<br>
�Test 56: check the sender field of the received message.<br>
�Test 56 expected result:<br>
�the sender field of the received message has value &quot;exchange.pmc.router-in&quot;.<br>
�Test 57: check the body fields of the received and the published messages.<br>
�Test 57 expected result:<br>
�the body fields of the received and the published messages are the same.<br>
�Test 58: check that the timestamp in an integer.<br>
�Test 58 expected result: the timestamp in an integer.<br>
�Test 59: check that the timestamp is greater than or equal to that of before publishing.<br>
�Test 59 expected result: the timestamp is greater than or equal to that of before publishing.<br>
�Test 60: check that the timestamp is less than or equal to that of now.<br>
�Test 60 expected result: the timestamp is less than or equal to that of now.<br>
�Test 61: try to receive a message from exchange.pmc.router-in in 8 seconds.<br>
�Test 61 expected result: a message is received from exchange.pmc.router-in in 8 seconds.<br>
�Test 62: decode the message as JSON.<br>
�Test 62 expected result: the message is decoded as JSON.<br>
�Test 63: check the sender field of the received message.<br>
�Test 63 expected result:<br>
�the sender field of the received message has value &quot;exchange.pmc.sf-in&quot;.<br>
�Test 64: check the body fields of the received and the published messages.<br>
�Test 64 expected result:<br>
�the body fields of the received and the published messages are the same.<br>
�Test 65: check that the timestamp in an integer.<br>
�Test 65 expected result: the timestamp in an integer.<br>
�Test 66: check that the timestamp is greater than or equal to that of before publishing.<br>
�Test 66 expected result: the timestamp is greater than or equal to that of before publishing.<br>
�Test 67: check that the timestamp is less than or equal to that of now.<br>
�Test 67 expected result: the timestamp is less than or equal to that of now.<br>
�Test 68: try to receive a message from exchange.pmc.cassidian-in in 8 seconds.<br>
�Test 68 expected result: a message is received from exchange.pmc.cassidian-in in 8 seconds.<br>
�Test 69: decode the message as JSON.<br>
�Test 69 expected result: the message is decoded as JSON.<br>
�Test 70: check the sender field of the received message.<br>
�Test 70 expected result:<br>
�the sender field of the received message has value &quot;exchange.pmc.router-in&quot;.<br>
�Test 71: check the body fields of the received and the published messages.<br>
�Test 71 expected result:<br>
�the body fields of the received and the published messages are the same.<br>
�Test 72: check that the timestamp in an integer.<br>
�Test 72 expected result: the timestamp in an integer.<br>
�Test 73: check that the timestamp is greater than or equal to that of before publishing.<br>
�Test 73 expected result: the timestamp is greater than or equal to that of before publishing.<br>
�Test 74: check that the timestamp is less than or equal to that of now.<br>
�Test 74 expected result: the timestamp is less than or equal to that of now.<br>
<br>
=cut<br>
<br>
use strict;<br>
<br>
use Net::RabbitMQ;<br>
use Test::More tests =&gt; 74;<br>
use JSON;<br>
use Time::HiRes qw(gettimeofday);<br>
<br>
use constant ROUTER_EXCHANGE � �=&gt; &#39;exchange.pmc.router-in&#39;;<br>
use constant ROUTER_CHANNEL � � =&gt; 1;<br>
use constant ROUTER_QUEUE � � � =&gt; &#39;queue.test.router-in&#39;;<br>
use constant SF_EXCHANGE � � � �=&gt; &#39;exchange.pmc.sf-in&#39;;<br>
use constant SF_CHANNEL � � � � =&gt; 2;<br>
use constant SF_QUEUE � � � � � =&gt; &#39;queue.test.sf-in&#39;;<br>
use constant CASSIDIAN_EXCHANGE =&gt; &#39;exchange.pmc.cassidian-in&#39;;<br>
use constant CASSIDIAN_CHANNEL �=&gt; 3;<br>
use constant CASSIDIAN_QUEUE � �=&gt; &#39;queue.test.cassidian-in&#39;;<br>
<br>
sub timestamp {<br>
 � �return int( gettimeofday() * 1000 );<br>
}<br>
<br>
system(<br>
&#39;service pmc-smpp stop &gt;&amp;2; service pmc-cassidian stop &gt;&amp;2; service pmc-email stop &gt;&amp;2; service pmc-sf stop &gt;&amp;2; service pmc-routing stop &gt;&amp;2&#39;<br>
);<br>
<br>
sleep 1; � �# Wait for the message-sending to stop.<br>
<br>
system(<br>
 � �&#39;rabbitmqctl stop_app; rabbitmqctl reset; rabbitmqctl start_app; mongo &lt;&lt;END<br>
use database<br>
db.dropDatabase();<br>
END&#39;<br>
);<br>
<br>
system(&#39;service pmc-sf start &gt;&amp;2; service pmc-routing start &gt;&amp;2&#39;);<br>
<br>
sleep 8; � �# Wait for Store &amp; Forward and Routing to start.<br>
<br>
my $json_text = &#39;{<br>
&quot;timestamp&quot; : 1330327514213,<br>
&quot;sender&quot; : &quot;&#39; . CASSIDIAN_EXCHANGE . &#39;&quot;,<br>
&quot;body&quot; : {<br>
&quot;type&quot; : &quot;dispatch&quot;,<br>
&quot;version&quot; : 1,<br>
&quot;id&quot; : &quot;8f970b1b-f8a3-4c78-aa24-3b8e2205648788&quot;,<br>
&quot;from&quot; : {<br>
&quot;type&quot; : &quot;ssi&quot;,<br>
&quot;address&quot; : &quot;16777215&quot;<br>
},<br>
&quot;to&quot; : {<br>
&quot;type&quot; : &quot;ssi&quot;,<br>
&quot;address&quot; : &quot;0&quot;<br>
},<br>
&quot;body&quot; : &quot;This is a test message.&quot;,<br>
&quot;ack_level&quot; : &quot;sent&quot;,<br>
&quot;valid_until&quot; : 9223372036854775807,<br>
&quot;auxiliary&quot; : {<br>
&quot;timestamp&quot; : 1325376000000,<br>
&quot;sdstl&quot; : {<br>
&quot;protocol_id&quot; : 130,<br>
&quot;message_reference&quot; : 42,<br>
&quot;short_report_allowed&quot; : true,<br>
&quot;protocol_data&quot; : {<br>
&quot;encoding&quot; : 0,<br>
&quot;timestamp&quot; : {<br>
&quot;month&quot; : 1,<br>
&quot;day&quot; : 1,<br>
&quot;hour&quot; : 0,<br>
&quot;minute&quot; : 0<br>
}<br>
}<br>
}<br>
}<br>
}<br>
}&#39;;<br>
<br>
my $mq_router = Net::RabbitMQ-&gt;new();<br>
$mq_router-&gt;connect( &quot;localhost&quot;, { user =&gt; &quot;guest&quot;, password =&gt; &quot;guest&quot; } );<br>
$mq_router-&gt;channel_open(ROUTER_CHANNEL);<br>
$mq_router-&gt;queue_declare(<br>
 � �ROUTER_CHANNEL,<br>
 � �ROUTER_QUEUE,<br>
 � �{<br>
 � � � �passive � � =&gt; 0,<br>
 � � � �durable � � =&gt; 1,<br>
 � � � �exclusive � =&gt; 0,<br>
 � � � �auto_delete =&gt; 0<br>
 � �}<br>
);<br>
$mq_router-&gt;queue_bind( ROUTER_CHANNEL, ROUTER_QUEUE, ROUTER_EXCHANGE, &#39;&#39; );<br>
$mq_router-&gt;purge( ROUTER_CHANNEL, ROUTER_QUEUE );<br>
$mq_router-&gt;consume( ROUTER_CHANNEL, ROUTER_QUEUE );<br>
<br>
my $mq_sf = Net::RabbitMQ-&gt;new();<br>
$mq_sf-&gt;connect( &quot;localhost&quot;, { user =&gt; &quot;guest&quot;, password =&gt; &quot;guest&quot; } );<br>
$mq_sf-&gt;channel_open(SF_CHANNEL);<br>
$mq_sf-&gt;exchange_declare(<br>
 � �SF_CHANNEL,<br>
 � �SF_EXCHANGE,<br>
 � �{<br>
 � � � �exchange_type =&gt; &#39;direct&#39;,<br>
 � � � �passive � � � =&gt; 0,<br>
 � � � �durable � � � =&gt; 1,<br>
 � � � �auto_delete � =&gt; 0<br>
 � �}<br>
);<br>
$mq_sf-&gt;queue_declare(<br>
 � �SF_CHANNEL,<br>
 � �SF_QUEUE,<br>
 � �{<br>
 � � � �passive � � =&gt; 0,<br>
 � � � �durable � � =&gt; 1,<br>
 � � � �exclusive � =&gt; 0,<br>
 � � � �auto_delete =&gt; 0<br>
 � �}<br>
);<br>
$mq_sf-&gt;queue_bind( SF_CHANNEL, SF_QUEUE, SF_EXCHANGE, &#39;&#39; );<br>
$mq_sf-&gt;purge( SF_CHANNEL, SF_QUEUE );<br>
$mq_sf-&gt;consume( SF_CHANNEL, SF_QUEUE );<br>
<br>
my $mq_cassidian = Net::RabbitMQ-&gt;new();<br>
$mq_cassidian-&gt;connect( &quot;localhost&quot;, { user =&gt; &quot;guest&quot;, password =&gt; &quot;guest&quot; } );<br>
$mq_cassidian-&gt;channel_open(CASSIDIAN_CHANNEL);<br>
$mq_cassidian-&gt;exchange_declare(<br>
 � �CASSIDIAN_CHANNEL,<br>
 � �CASSIDIAN_EXCHANGE,<br>
 � �{<br>
 � � � �exchange_type =&gt; &#39;direct&#39;,<br>
 � � � �passive � � � =&gt; 0,<br>
 � � � �durable � � � =&gt; 1,<br>
 � � � �auto_delete � =&gt; 0<br>
 � �}<br>
);<br>
$mq_cassidian-&gt;queue_declare(<br>
 � �CASSIDIAN_CHANNEL,<br>
 � �CASSIDIAN_QUEUE,<br>
 � �{<br>
 � � � �passive � � =&gt; 0,<br>
 � � � �durable � � =&gt; 1,<br>
 � � � �exclusive � =&gt; 0,<br>
 � � � �auto_delete =&gt; 0<br>
 � �}<br>
);<br>
$mq_cassidian-&gt;queue_bind( CASSIDIAN_CHANNEL, CASSIDIAN_QUEUE,<br>
 � �CASSIDIAN_EXCHANGE, &#39;&#39; );<br>
$mq_cassidian-&gt;purge( CASSIDIAN_CHANNEL, CASSIDIAN_QUEUE );<br>
$mq_cassidian-&gt;consume( CASSIDIAN_CHANNEL, CASSIDIAN_QUEUE );<br>
<br>
my $before = timestamp();<br>
<br>
$mq_router-&gt;publish(<br>
 � �ROUTER_CHANNEL,<br>
 � �&#39;&#39;,<br>
 � �$json_text,<br>
 � �{<br>
<br>
 � � � �# Options<br>
 � � � �exchange =&gt; ROUTER_EXCHANGE<br>
 � �},<br>
 � �{<br>
<br>
 � � � �# Props<br>
 � � � �content_encoding =&gt; &quot;UTF-8&quot;,<br>
 � � � �content_type � � =&gt; &quot;application/json&quot;<br>
 � �}<br>
);<br>
<br>
my $sent = decode_json($json_text);<br>
my $message;<br>
eval {<br>
 � �local $SIG{ALRM} = sub { die &quot;Timeout\n&quot; };<br>
 � �alarm 8;<br>
 � �$message = $mq_router-&gt;recv();<br>
 � �alarm 0;<br>
};<br>
is( $@, &#39;&#39;, &#39;A message was received from queue&#39; );<br>
my $json;<br>
eval { $json = decode_json( $message-&gt;{&#39;body&#39;} ); };<br>
is( $@, &#39;&#39;, &#39;A JSON message received&#39; );<br>
is( $json-&gt;{&#39;sender&#39;}, $sent-&gt;{&#39;sender&#39;}, &#39;sender &#39; . $sent-&gt;{&#39;sender&#39;} );<br>
is_deeply( $json-&gt;{&#39;body&#39;}, $sent-&gt;{&#39;body&#39;}, &#39;body the same&#39; );<br>
is( $json-&gt;{&#39;timestamp&#39;}, $sent-&gt;{&#39;timestamp&#39;},<br>
 � �&quot;timestamp &quot; . $sent-&gt;{&#39;timestamp&#39;} );<br>
<br>
undef $message;<br>
eval {<br>
 � �local $SIG{ALRM} = sub { die &quot;Timeout\n&quot; };<br>
 � �alarm 8;<br>
 � �$message = $mq_sf-&gt;recv();<br>
 � �alarm 0;<br>
};<br>
is( $@, &#39;&#39;, &#39;A message was received&#39; );<br>
undef $json;<br>
eval { $json = decode_json( $message-&gt;{&#39;body&#39;} ); };<br>
is( $@, &#39;&#39;, &#39;A JSON message received&#39; );<br>
is( $json-&gt;{&#39;sender&#39;}, ROUTER_EXCHANGE, &#39;sender &#39; . ROUTER_EXCHANGE );<br>
is_deeply( $json-&gt;{&#39;body&#39;}, $sent-&gt;{&#39;body&#39;}, &#39;body the same&#39; );<br>
like( $json-&gt;{&#39;timestamp&#39;}, qr/^\d+$/, &quot;timestamp an integer&quot; );<br>
ok( $json-&gt;{&#39;timestamp&#39;} &gt;= $before,<br>
 � �&#39;timestamp greater than or equal to that of before publishing&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &lt; $before&quot;);<br>
my $now = timestamp();<br>
ok( $json-&gt;{&#39;timestamp&#39;} &lt;= $now,<br>
 � �&#39;timestamp less than or equal to that of now&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &gt; $now&quot;);<br>
<br>
undef $message;<br>
eval {<br>
 � �local $SIG{ALRM} = sub { die &quot;Timeout\n&quot; };<br>
 � �alarm 8;<br>
 � �$message = $mq_router-&gt;recv();<br>
 � �alarm 0;<br>
};<br>
is( $@, &#39;&#39;, &#39;A message was received&#39; );<br>
undef $json;<br>
eval { $json = decode_json( $message-&gt;{&#39;body&#39;} ); };<br>
is( $@, � � � � � � � �&#39;&#39;, � � � � �&#39;A JSON message received&#39; );<br>
is( $json-&gt;{&#39;sender&#39;}, SF_EXCHANGE, &#39;sender &#39; . SF_EXCHANGE );<br>
is_deeply( $json-&gt;{&#39;body&#39;}, $sent-&gt;{&#39;body&#39;}, &#39;body the same&#39; );<br>
like( $json-&gt;{&#39;timestamp&#39;}, qr/^\d+$/, &quot;timestamp an integer&quot; );<br>
ok( $json-&gt;{&#39;timestamp&#39;} &gt;= $before,<br>
 � �&#39;timestamp greater than or equal to that of before publishing&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &lt; $before&quot;);<br>
$now = timestamp();<br>
ok( $json-&gt;{&#39;timestamp&#39;} &lt;= $now,<br>
 � �&#39;timestamp less than or equal to that of now&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &gt; $now&quot;);<br>
<br>
undef $message;<br>
eval {<br>
 � �local $SIG{ALRM} = sub { die &quot;Timeout\n&quot; };<br>
 � �alarm 8;<br>
 � �$message = $mq_router-&gt;recv();<br>
 � �alarm 0;<br>
};<br>
is( $@, &#39;&#39;, &#39;A message was received&#39; );<br>
undef $json;<br>
eval { $json = decode_json( $message-&gt;{&#39;body&#39;} ); };<br>
is( $@, � � � � � � � �&#39;&#39;, � � � � �&#39;A JSON message received&#39; );<br>
is( $json-&gt;{&#39;sender&#39;}, SF_EXCHANGE, &#39;sender &#39; . SF_EXCHANGE );<br>
like( $json-&gt;{&#39;timestamp&#39;}, qr/^\d+$/, &quot;timestamp an integer&quot; );<br>
ok( $json-&gt;{&#39;timestamp&#39;} &gt;= $before,<br>
 � �&#39;timestamp greater than or equal to that of before publishing&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &lt; $before&quot;);<br>
$now = timestamp();<br>
ok( $json-&gt;{&#39;timestamp&#39;} &lt;= $now,<br>
 � �&#39;timestamp less than or equal to that of now&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &gt; $now&quot;);<br>
is( $json-&gt;{&#39;body&#39;}-&gt;{&#39;id&#39;}, $sent-&gt;{&#39;body&#39;}-&gt;{&#39;id&#39;}, &#39;id the same&#39; );<br>
is( $json-&gt;{&#39;body&#39;}-&gt;{&#39;ack_type&#39;}, &#39;processed&#39;, &#39;ack_type processed&#39; );<br>
is_deeply(<br>
 � �$json-&gt;{&#39;body&#39;}-&gt;{&#39;from&#39;},<br>
 � �$sent-&gt;{&#39;body&#39;}-&gt;{&#39;to&#39;},<br>
 � �&#39;from is the same as to of sent&#39;<br>
);<br>
is( $json-&gt;{&#39;body&#39;}-&gt;{&#39;type&#39;}, � �&#39;ack&#39;, &#39;type is ack&#39; );<br>
is( $json-&gt;{&#39;body&#39;}-&gt;{&#39;version&#39;}, 1, � � &#39;version is 1&#39; );<br>
<br>
my $end = time() + 8;<br>
undef $message;<br>
do {<br>
 � �eval {<br>
 � � � �$message = $mq_cassidian-&gt;get( CASSIDIAN_CHANNEL, CASSIDIAN_QUEUE );<br>
 � �};<br>
 � �if ($@) {<br>
 � � � �diag($@);<br>
 � �}<br>
} until ( defined $message or time() &gt; $end or $@ );<br>
ok( defined $message, &#39;A message was received&#39; );<br>
undef $json;<br>
eval { $json = decode_json( $message-&gt;{&#39;body&#39;} ); };<br>
is( $@, &#39;&#39;, &#39;A JSON message received&#39; );<br>
is( $json-&gt;{&#39;sender&#39;}, ROUTER_EXCHANGE, &#39;sender &#39; . ROUTER_EXCHANGE );<br>
is_deeply( $json-&gt;{&#39;body&#39;}, $sent-&gt;{&#39;body&#39;}, &#39;body the same&#39; );<br>
like( $json-&gt;{&#39;timestamp&#39;}, qr/^\d+$/, &quot;timestamp an integer&quot; );<br>
ok( $json-&gt;{&#39;timestamp&#39;} &gt;= $before,<br>
 � �&#39;timestamp greater than or equal to that of before publishing&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &lt; $before&quot;);<br>
$now = timestamp();<br>
ok( $json-&gt;{&#39;timestamp&#39;} &lt;= $now,<br>
 � �&#39;timestamp less than or equal to that of now&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &gt; $now&quot;);<br>
<br>
$end = time() + 8;<br>
note(&quot;Trying to receive an Ack from Cassidian exchange&quot;);<br>
undef $message;<br>
do {<br>
 � �eval {<br>
 � � � �$message = $mq_cassidian-&gt;get( CASSIDIAN_CHANNEL, CASSIDIAN_QUEUE );<br>
 � �};<br>
 � �if ($@) {<br>
 � � � �diag($@);<br>
 � �}<br>
} until ( defined $message or time() &gt; $end or $@ );<br>
ok( defined $message, &#39;A message was received&#39; );<br>
undef $json;<br>
eval { $json = decode_json( $message-&gt;{&#39;body&#39;} ); };<br>
is( $@, &#39;&#39;, &#39;A JSON message received&#39; );<br>
is( $json-&gt;{&#39;sender&#39;}, ROUTER_EXCHANGE, &#39;sender &#39; . ROUTER_EXCHANGE );<br>
like( $json-&gt;{&#39;timestamp&#39;}, qr/^\d+$/, &quot;timestamp an integer&quot; );<br>
ok( $json-&gt;{&#39;timestamp&#39;} &gt;= $before,<br>
 � �&#39;timestamp greater than or equal to that of before publishing&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &lt; $before&quot;);<br>
$now = timestamp();<br>
ok( $json-&gt;{&#39;timestamp&#39;} &lt;= $now,<br>
 � �&#39;timestamp less than or equal to that of now&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &gt; $now&quot;);<br>
is( $json-&gt;{&#39;body&#39;}-&gt;{&#39;id&#39;}, $sent-&gt;{&#39;body&#39;}-&gt;{&#39;id&#39;}, &#39;id the same&#39; );<br>
is( $json-&gt;{&#39;body&#39;}-&gt;{&#39;ack_type&#39;}, &#39;processed&#39;, &#39;ack_type processed&#39; );<br>
is_deeply(<br>
 � �$json-&gt;{&#39;body&#39;}-&gt;{&#39;from&#39;},<br>
 � �$sent-&gt;{&#39;body&#39;}-&gt;{&#39;to&#39;},<br>
 � �&#39;from is the same as to of sent&#39;<br>
);<br>
is( $json-&gt;{&#39;body&#39;}-&gt;{&#39;type&#39;}, � �&#39;ack&#39;, &#39;type is ack&#39; );<br>
is( $json-&gt;{&#39;body&#39;}-&gt;{&#39;version&#39;}, 1, � � &#39;version is 1&#39; );<br>
<br>
my $ack = &#39;{<br>
&quot;timestamp&quot; : 1328020064358,<br>
&quot;sender&quot; : &quot;&#39; . CASSIDIAN_EXCHANGE . &#39;&quot;,<br>
&quot;body&quot; : {<br>
&quot;type&quot; : &quot;ack&quot;,<br>
&quot;version&quot; : 1,<br>
&quot;id&quot; : &quot;8f970b1b-f8a3-4c78-aa24-3b8e2205648788&quot;,<br>
&quot;from&quot; : {<br>
&quot;type&quot; : &quot;ssi&quot;,<br>
&quot;address&quot; : &quot;0&quot;<br>
},<br>
&quot;ack_type&quot; : &quot;sent&quot;,<br>
&quot;auxiliary&quot; : {<br>
&quot;timestamp&quot; : 1325376000000,<br>
&quot;original_message&quot; : &#39; . encode_json( $sent-&gt;{&#39;body&#39;} ) . &#39;,<br>
&quot;sdstl&quot; : {<br>
&quot;protocol_id&quot; : 130,<br>
&quot;message_reference&quot; : 42,<br>
&quot;short_report_allowed&quot; : true,<br>
&quot;protocol_data&quot; : {<br>
&quot;encoding&quot; : 0,<br>
&quot;timestamp&quot; : {<br>
&quot;month&quot; : 1,<br>
&quot;day&quot; : 1,<br>
&quot;hour&quot; : 0,<br>
&quot;minute&quot; : 0<br>
}<br>
}<br>
}<br>
}<br>
}<br>
}&#39;;<br>
$sent � = decode_json($ack);<br>
$before = timestamp();<br>
<br>
$mq_router-&gt;publish(<br>
 � �ROUTER_CHANNEL,<br>
 � �&#39;&#39;, $ack,<br>
 � �{<br>
<br>
 � � � �# Options<br>
 � � � �exchange =&gt; ROUTER_EXCHANGE<br>
 � �},<br>
 � �{<br>
<br>
 � � � �# Props<br>
 � � � �content_encoding =&gt; &quot;UTF-8&quot;,<br>
 � � � �content_type � � =&gt; &quot;application/json&quot;<br>
 � �}<br>
);<br>
<br>
undef $message;<br>
eval {<br>
 � �local $SIG{ALRM} = sub { die &quot;Timeout\n&quot; };<br>
 � �alarm 8;<br>
 � �$message = $mq_router-&gt;recv();<br>
 � �alarm 0;<br>
};<br>
is( $@, &#39;&#39;, &#39;A message was received&#39; );<br>
undef $json;<br>
eval { $json = decode_json( $message-&gt;{&#39;body&#39;} ); };<br>
is( $@, &#39;&#39;, &#39;A JSON message received&#39; );<br>
is( $json-&gt;{&#39;timestamp&#39;}, $sent-&gt;{&#39;timestamp&#39;},<br>
 � �&#39;timestamp &#39; . $sent-&gt;{&#39;timestamp&#39;} )<br>
 �or diag( $message-&gt;{&#39;body&#39;} );<br>
is( $json-&gt;{&#39;sender&#39;}, CASSIDIAN_EXCHANGE, &#39;sender &#39; . CASSIDIAN_EXCHANGE )<br>
 �or diag( $message-&gt;{&#39;body&#39;} );<br>
is_deeply( $json-&gt;{&#39;body&#39;}, $sent-&gt;{&#39;body&#39;}, &#39;body the same&#39; )<br>
 �or diag( $message-&gt;{&#39;body&#39;} );<br>
<br>
undef $message;<br>
eval {<br>
 � �local $SIG{ALRM} = sub { die &quot;Timeout\n&quot; };<br>
 � �alarm 8;<br>
 � �$message = $mq_sf-&gt;recv();<br>
 � �alarm 0;<br>
};<br>
is( $@, &#39;&#39;, &#39;A message was received&#39; );<br>
undef $json;<br>
eval { $json = decode_json( $message-&gt;{&#39;body&#39;} ); };<br>
is( $@, &#39;&#39;, &#39;A JSON message received&#39; );<br>
is( $json-&gt;{&#39;sender&#39;}, ROUTER_EXCHANGE, &#39;sender &#39; . ROUTER_EXCHANGE );<br>
is_deeply( $json-&gt;{&#39;body&#39;}, $sent-&gt;{&#39;body&#39;}, &#39;body the same&#39; );<br>
like( $json-&gt;{&#39;timestamp&#39;}, qr/^\d+$/, &quot;timestamp an integer&quot; );<br>
ok( $json-&gt;{&#39;timestamp&#39;} &gt;= $before,<br>
 � �&#39;timestamp greater than or equal to that of before publishing&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &lt; $before&quot;);<br>
$now = timestamp();<br>
ok( $json-&gt;{&#39;timestamp&#39;} &lt;= $now,<br>
 � �&#39;timestamp less than or equal to that of now&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &gt; $now&quot;);<br>
<br>
undef $message;<br>
eval {<br>
 � �local $SIG{ALRM} = sub { die &quot;Timeout\n&quot; };<br>
 � �alarm 8;<br>
 � �$message = $mq_router-&gt;recv();<br>
 � �alarm 0;<br>
};<br>
is( $@, &#39;&#39;, &#39;A message was received&#39; );<br>
undef $json;<br>
eval { $json = decode_json( $message-&gt;{&#39;body&#39;} ); };<br>
is( $@, � � � � � � � �&#39;&#39;, � � � � �&#39;A JSON message received&#39; );<br>
is( $json-&gt;{&#39;sender&#39;}, SF_EXCHANGE, &#39;sender &#39; . SF_EXCHANGE );<br>
is_deeply( $json-&gt;{&#39;body&#39;}, $sent-&gt;{&#39;body&#39;}, &#39;body the same&#39; );<br>
like( $json-&gt;{&#39;timestamp&#39;}, qr/^\d+$/, &quot;timestamp an integer&quot; );<br>
ok( $json-&gt;{&#39;timestamp&#39;} &gt;= $before,<br>
 � �&#39;timestamp greater than or equal to that of before publishing&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &lt; $before&quot;);<br>
$now = timestamp();<br>
ok( $json-&gt;{&#39;timestamp&#39;} &lt;= $now,<br>
 � �&#39;timestamp less than or equal to that of now&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &gt; $now&quot;);<br>
<br>
undef $message;<br>
eval {<br>
 � �local $SIG{ALRM} = sub { die &quot;Timeout\n&quot; };<br>
 � �alarm 8;<br>
 � �$message = $mq_cassidian-&gt;recv();<br>
 � �alarm 0;<br>
};<br>
is( $@, &#39;&#39;, &#39;A message was received&#39; );<br>
undef $json;<br>
eval { $json = decode_json( $message-&gt;{&#39;body&#39;} ); };<br>
is( $@, &#39;&#39;, &#39;A JSON message received&#39; );<br>
is( $json-&gt;{&#39;sender&#39;}, ROUTER_EXCHANGE, &#39;sender &#39; . ROUTER_EXCHANGE );<br>
is_deeply( $json-&gt;{&#39;body&#39;}, $sent-&gt;{&#39;body&#39;}, &#39;body the same&#39; );<br>
like( $json-&gt;{&#39;timestamp&#39;}, qr/^\d+$/, &quot;timestamp an integer&quot; );<br>
ok( $json-&gt;{&#39;timestamp&#39;} &gt;= $before,<br>
 � �&#39;timestamp greater than or equal to that of before publishing&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &lt; $before&quot;);<br>
$now = timestamp();<br>
ok( $json-&gt;{&#39;timestamp&#39;} &lt;= $now,<br>
 � �&#39;timestamp less than or equal to that of now&#39; )<br>
 �or diag(&quot;$json-&gt;{&#39;timestamp&#39;} &gt; $now&quot;);<br>
<br>
END {<br>
 � �$mq_sf-&gt;queue_unbind( SF_CHANNEL, SF_QUEUE, SF_EXCHANGE, &#39;&#39; );<br>
 � �$mq_router-&gt;queue_unbind( ROUTER_CHANNEL, ROUTER_QUEUE, ROUTER_EXCHANGE,<br>
 � � � �&#39;&#39; );<br>
 � �$mq_cassidian-&gt;queue_unbind( CASSIDIAN_CHANNEL, CASSIDIAN_QUEUE,<br>
 � � � �CASSIDIAN_EXCHANGE, &#39;&#39; );<br>
 � �system(<br>
&#39;service pmc-smpp start &gt;&amp;2; service pmc-cassidian start &gt;&amp;2; service pmc-email start &gt;&amp;2&#39;<br>
 � �);<br>
}<br>
<br>
regards, Matti Linnanvuori<br>
</blockquote></div><br></div></div></div>