Is There a Way to Prevent MassTransit From Taking Down Our Service? - rabbitmq

We're seeing one exception that, if I recall correctly, should be fixed in MT 3.0 (we're on 3.1) we see this when we have our environment under a very high load:
Exception Info: RabbitMQ.Client.Exceptions.AlreadyClosedException
Stack:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__1(System.Object)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
This exception is causing our windows service to crash and someone has to go start it back up. Is there an event or some configuration we can setup at a higher level to handle these unforeseen scenarios?
I know there are bus events, but no even specific to exceptions outside of my message handling.
I also saw there is exception handling, unfortunately this is only good for scenarios where there's an error while processing a message. Not for when RabbitMQ throws an exception unrelated to retrieving or sending a message.
I just added some logging and service level restart logic, will update this with more details if available in the future.
AppDomain.CurrentDomain.UnhandledException += UnhandledException;
public void UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
// Shut down, dispose, reinitialize internal objects and log messages.
}
Edit 1 - RabbitMQ Logs
We saw this error at 11:37:47, in all 3 of the rabbitmq servers we're seeing these type of logs:
=INFO REPORT==== 5-May-2016::11:37:06 ===
accepting AMQP connection <0.925.14> (10.50.0.3:59625 -> 10.50.0.123:5672)
=ERROR REPORT==== 5-May-2016::11:37:10 ===
closing AMQP connection <0.917.14> (10.50.0.3:59588 -> 10.50.0.123:5672):
{handshake_timeout,handshake}
=WARNING REPORT==== 5-May-2016::11:37:15 ===
closing AMQP connection <0.614.14> (10.50.0.3:58645 -> 10.50.0.123:5672):
connection_closed_abruptly
=ERROR REPORT==== 5-May-2016::11:37:16 ===
closing AMQP connection <0.925.14> (10.50.0.3:59625 -> 10.50.0.123:5672):
{handshake_timeout,handshake}
=INFO REPORT==== 5-May-2016::11:37:17 ===
accepting AMQP connection <0.941.14> (10.50.0.3:59665 -> 10.50.0.123:5672)
=WARNING REPORT==== 5-May-2016::11:37:24 ===
closing AMQP connection <0.642.14> (10.50.0.3:58726 -> 10.50.0.123:5672):
connection_closed_abruptly
=INFO REPORT==== 5-May-2016::11:37:25 ===
accepting AMQP connection <0.955.14> (10.50.0.3:59774 -> 10.50.0.123:5672)
=WARNING REPORT==== 5-May-2016::11:37:27 ===
closing AMQP connection <0.955.14> (10.50.0.3:59774 -> 10.50.0.123:5672):
connection_closed_abruptly
=ERROR REPORT==== 5-May-2016::11:37:27 ===
closing AMQP connection <0.941.14> (10.50.0.3:59665 -> 10.50.0.123:5672):
{handshake_timeout,handshake}
=INFO REPORT==== 5-May-2016::11:37:29 ===
accepting AMQP connection <0.962.14> (10.50.0.3:59796 -> 10.50.0.123:5672)
=WARNING REPORT==== 5-May-2016::11:37:30 ===
closing AMQP connection <0.670.14> (10.50.0.3:58769 -> 10.50.0.123:5672):
connection_closed_abruptly
=INFO REPORT==== 5-May-2016::11:37:35 ===
accepting AMQP connection <0.972.14> (10.50.0.3:59814 -> 10.50.0.123:5672)
=INFO REPORT==== 5-May-2016::11:37:36 ===
accepting AMQP connection <0.975.14> (10.50.0.3:59824 -> 10.50.0.123:5672)
=WARNING REPORT==== 5-May-2016::11:37:36 ===
closing AMQP connection <0.975.14> (10.50.0.3:59824 -> 10.50.0.123:5672):
connection_closed_abruptly
=ERROR REPORT==== 5-May-2016::11:37:39 ===
closing AMQP connection <0.962.14> (10.50.0.3:59796 -> 10.50.0.123:5672):
{handshake_timeout,handshake}
=INFO REPORT==== 5-May-2016::11:37:44 ===
accepting AMQP connection <0.993.14> (10.50.0.3:59872 -> 10.50.0.123:5672)
=WARNING REPORT==== 5-May-2016::11:37:45 ===
closing AMQP connection <0.705.14> (10.50.0.3:58934 -> 10.50.0.123:5672):
connection_closed_abruptly
=ERROR REPORT==== 5-May-2016::11:37:45 ===
closing AMQP connection <0.972.14> (10.50.0.3:59814 -> 10.50.0.123:5672):
{handshake_timeout,handshake}
=INFO REPORT==== 5-May-2016::11:37:46 ===
accepting AMQP connection <0.1005.14> (10.50.0.3:59881 -> 10.50.0.123:5672)
=WARNING REPORT==== 5-May-2016::11:37:46 ===
closing AMQP connection <0.1005.14> (10.50.0.3:59881 -> 10.50.0.123:5672):
connection_closed_abruptly
=INFO REPORT==== 5-May-2016::11:37:47 ===
accepting AMQP connection <0.1010.14> (10.50.0.3:59892 -> 10.50.0.123:5672)
Going back a few minutes we see blocks of this several times:
=INFO REPORT==== 5-May-2016::11:28:25 ===
Mirrored queue 'bus-JEMSO04-w3wp-ktbyyynsicyfb1scbdjzj6targ' in vhost 'Beta': Adding mirror on node rabbit#redisd01: <18045.5072.16>
=INFO REPORT==== 5-May-2016::11:28:25 ===
Mirrored queue 'bus-JEMSO04-w3wp-ktbyyynsicyfb1scbdjzj6targ' in vhost 'Beta': Adding mirror on node rabbit#redisd02: <6520.2073.16>
=INFO REPORT==== 5-May-2016::11:28:25 ===
Mirrored queue 'bus-JEMSO04-w3wp-ktbyyynsicyfb1scbdjzj6targ' in vhost 'Beta': Synchronising: 0 messages to synchronise
=INFO REPORT==== 5-May-2016::11:28:25 ===
Mirrored queue 'bus-JEMSO04-w3wp-ktbyyynsicyfb1scbdjzj6targ' in vhost 'Beta': Synchronising: all slaves already synced
=INFO REPORT==== 5-May-2016::11:28:25 ===
Mirrored queue 'bus-JEMSO04-w3wp-ktbyyynsicyfb1scbdjzj6targ' in vhost 'Beta': Synchronising: 0 messages to synchronise
=INFO REPORT==== 5-May-2016::11:28:25 ===
Mirrored queue 'bus-JEMSO04-w3wp-ktbyyynsicyfb1scbdjzj6targ' in vhost 'Beta': Synchronising: all slaves already synced
=ERROR REPORT==== 5-May-2016::11:28:26 ===
closing AMQP connection <0.32168.13> (10.50.0.3:47716 -> 10.50.0.123:5672):
{handshake_timeout,handshake}
Edit 2 - Updated to MassTransit 3.3.3
We have a new issue after upgrading, this is coming from our consumer and is not under load:
MassTransit.Util.TaskSupervisor Error: 0 : Failed to close scope MassTransit.RabbitMqTransport.Pipeline.RabbitMqBasicConsumer - rabbitmq://rabbitmqdlb.jsa.local:5672/LocalDev/bus-MRHODEN-DT-Se
rvice.vshost-xabyyydu3ecy84dibdjamdsbrb?prefetch=16, System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at MassTransit.RabbitMqTransport.Pipeline.RabbitMqBasicConsumer.<Stop>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at MassTransit.Util.TaskSupervisorExtensions.<>c__DisplayClass2_0.<<CreateParticipant>b__0>d.MoveNext()

Related

Rabbitmq server crash randomly occur and I don't know why

I want to know the cause of Rabbitmq crash which randomly occur. can you let me know what kind of causes could be considered?
Also my team should manually restart the rabbitmq when crash happens, so I want to know if there is a way to restart rabbitmq server automatically.
Here is the error report when rabbitmq crash occur:
=WARNING REPORT==== 6-Dec-2017::07:56:43 ===
closing AMQP connection <0.4387.0> (000000:23070 -> 00000:5672, vhost: '/', user: '00000'):
client unexpectedly closed TCP connection
Also this is part of sasl.gsd fild :
=SUPERVISOR REPORT==== 7-Dec-2017::10:03:15 ===
Supervisor: {local,sockjs_session_sup}
Context: child_terminated
Reason: {function_clause,
[{gen_server,cast,
[{},sockjs_closed],
[{file,"gen_server.erl"},{line,218}]},
{rabbit_ws_sockjs,service_stomp,3,
[{file,"src/rabbit_ws_sockjs.erl"},{line,150}]},
{sockjs_session,emit,2,
[{file,"src/sockjs_session.erl"},{line,173}]},
{sockjs_session,terminate,2,
[{file,"src/sockjs_session.erl"},{line,311}]},
{gen_server,try_terminate,3,
[{file,"gen_server.erl"},{line,629}]},
{gen_server,terminate,7,
[{file,"gen_server.erl"},{line,795}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,247}]}]}
Offender: [{pid,<0.20883.1160>},
{id,undefined},
{mfargs,
{sockjs_session,start_link,
["pd4tvvi0",
{service,"/stomp",
#Fun<rabbit_ws_sockjs.1.47892404>,{},
"//cdn.jsdelivr.net/sockjs/1.0.3/sockjs.min.js",
false,true,5000,25000,131072,
#Fun<rabbit_ws_sockjs.0.47892404>,undefined},
[{peername,{{172,31,6,213},9910}},
{sockname,{{172,31,5,49},15674}},
{path,"/stomp/744/pd4tvvi0/htmlfile"},
{headers,[]},
{socket,#Port<0.12491352>}]]}},
{restart_type,transient},
{shutdown,5000},
{child_type,worker}]
=CRASH REPORT==== 7-Dec-2017::10:03:20 ===
crasher:
initial call: sockjs_session:init/1
pid: <0.25851.1160>
registered_name: []
exception exit: {function_clause,
[{gen_server,cast,
[{},sockjs_closed],
[{file,"gen_server.erl"},{line,218}]},
{rabbit_ws_sockjs,service_stomp,3,
[{file,"src/rabbit_ws_sockjs.erl"},{line,150}]},
{sockjs_session,emit,2,
[{file,"src/sockjs_session.erl"},{line,173}]},
{sockjs_session,terminate,2,
[{file,"src/sockjs_session.erl"},{line,311}]},
{gen_server,try_terminate,3,
[{file,"gen_server.erl"},{line,629}]},
{gen_server,terminate,7,
[{file,"gen_server.erl"},{line,795}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,247}]}]}
in function gen_server:terminate/7 (gen_server.erl, line 800)
ancestors: [sockjs_session_sup,<0.177.0>]
messages: []
links: [<0.178.0>]
dictionary: []
trap_exit: true
status: running
heap_size: 987
stack_size: 27
reductions: 175
neighbours:
Please check out the error report I posted above and let me know the causes of rabbitmq crash and the way to automatically restart rabbitmq server.
Thanks!!

Rabbitmq's management plugin's aliveness-test timing out for all cluster nodes

I was doing POC for aliveness-test and saw a strange scenario, where it started timing out for all the cluster nodes. I am planning to use application level health check in HAProxy using this aliveness-test API. But this scenario scared me as HAProxy started showing all the cluster nodes as DOWN when aliveness-test was timing out for all the cluster nodes But the rabbitmq server port was connectable during that time. As per the documentation, rabbitmq management tool (which listens to port 15672) can be assumed connectable while server (which listens at port 5672) is up and running.
When I was restarting rabbit nodes, it was going in the same state.
It resumed and started returning response code 200 when I killed rabbitmq processes in all the hosts using kill -9 and started the app gracefully.
how this can be avoided?
Putting some error logs from one of the node------
=INFO REPORT==== 7-Jul-2017::16:05:18 ===
Mirrored queue 'aliveness-test' in vhost '/': Slave <rabbit#pgperf-rabbitmq2.1.26928.0> saw deaths of mirrors <rabbit#pgperf-rabbitmq1.1.18235.0>
=WARNING REPORT==== 7-Jul-2017::16:05:18 ===
Mnesia('rabbit#pgperf-rabbitmq2'): ** WARNING ** Mnesia is overloaded: {dump_log,write_threshold}
=ERROR REPORT==== 7-Jul-2017::16:05:18 ===
** Generic server <0.27470.0> terminating
** Last message in was {'DOWN',#Ref<0.0.24.29729>,process,<7887.11927.0>,
noproc}
** When Server state == {state,
{20,<0.27470.0>},
{{17,<7888.18916.0>},#Ref<0.0.24.29728>},
{{10,<7887.11927.0>},#Ref<0.0.24.29729>},
{resource,<<"/">>,queue,<<"aliveness-test">>},
rabbit_mirror_queue_slave,
{21,
[{{10,<7887.11927.0>},
{view_member,
{10,<7887.11927.0>},
[],
{20,<0.27470.0>},
{14,<7888.18825.0>}}},
{{12,<0.26929.0>},
{view_member,
{12,<0.26929.0>},
[],
{14,<7888.18825.0>},
{17,<7888.18916.0>}}},
{{14,<7888.18825.0>},
{view_member,
{14,<7888.18825.0>},
[],
{10,<7887.11927.0>},
{12,<0.26929.0>}}},
{{17,<7888.18916.0>},
{view_member,
{17,<7888.18916.0>},
[],
{12,<0.26929.0>},
{20,<0.27470.0>}}},
{{20,<0.27470.0>},
{view_member,
{20,<0.27470.0>},
[],
{17,<7888.18916.0>},
{10,<7887.11927.0>}}}]},
-1,
[{{10,<7887.11927.0>},{member,{[],[]},1,1}},
{{12,<0.26929.0>},
{member,{[{1,process_death}],[]},1,-1}},
{{14,<7888.18825.0>},{member,{[],[]},0,0}},
{{17,<7888.18916.0>},{member,{[],[]},-1,-1}},
{{20,<0.27470.0>},{member,{[],[]},-1,-1}}],
[<0.27469.0>],
{[],[]},
[],0,undefined,
#Fun<rabbit_misc.execute_mnesia_transaction.1>,
false}
** Reason for termination ==
** {bad_return_value,
{error,
{function_clause,
[{gm,check_membership,
[{20,<0.27470.0>},{error,not_found}],
[{file,"src/gm.erl"},{line,1590}]},
{gm,'-record_dead_member_in_group/5-fun-1-',4,
[{file,"src/gm.erl"},{line,1132}]},
{mnesia_tm,apply_fun,3,[{file,"mnesia_tm.erl"},{line,833}]},
{mnesia_tm,execute_transaction,5,
[{file,"mnesia_tm.erl"},{line,808}]},
{rabbit_misc,'-execute_mnesia_transaction/1-fun-0-',1,
[{file,"src/rabbit_misc.erl"},{line,537}]},
{worker_pool_worker,'-run/2-fun-0-',3,
[{file,"src/worker_pool_worker.erl"},{line,77}]}]}}}
=ERROR REPORT==== 7-Jul-2017::16:05:18 ===
** Generic server <0.27469.0> terminating
** Last message in was {'EXIT',<0.27470.0>,
{bad_return_value,
{error,
{function_clause,
[{gm,check_membership,
[{20,<0.27470.0>},{error,not_found}],
[{file,"src/gm.erl"},{line,1590}]},
{gm,'-record_dead_member_in_group/5-fun-1-',4,
[{file,"src/gm.erl"},{line,1132}]},
{mnesia_tm,apply_fun,3,
[{file,"mnesia_tm.erl"},{line,833}]},
{mnesia_tm,execute_transaction,5,
[{file,"mnesia_tm.erl"},{line,808}]},
{rabbit_misc,
'-execute_mnesia_transaction/1-fun-0-',1,
[{file,"src/rabbit_misc.erl"},{line,537}]},
{worker_pool_worker,'-run/2-fun-0-',3,
[{file,"src/worker_pool_worker.erl"},
{line,77}]}]}}}}
** When Server state == {state,
{amqqueue,
{resource,<<"/">>,queue,<<"aliveness-test">>},
false,false,none,[],<7888.18913.0>,
[<7887.11753.0>],
[<7887.11753.0>],
['rabbit#pgpdr-rabbitmq2'],
[{vhost,<<"/">>},
{name,<<"ha-all">>},
{pattern,<<>>},
{'apply-to',<<"all">>},
{definition,
[{<<"ha-mode">>,<<"all">>},
{<<"ha-sync-mode">>,<<"automatic">>}]},
{priority,0}],
[{<7888.18916.0>,<7888.18913.0>},
{<7887.11774.0>,<7887.11753.0>}],
[],live},
<0.27470.0>,rabbit_priority_queue,
{passthrough,rabbit_variable_queue,
{vqstate,
{0,{[],[]}},
{0,{[],[]}},
{delta,undefined,0,undefined},
{0,{[],[]}},
{0,{[],[]}},
0,
{0,nil},
{0,nil},
{0,nil},
{qistate,
"/paytm/rabbitmq/mnesia/rabbit#pgperf-rabbitmq2/queues/1EZ1LHRKWKS0CPF59OD5ZBSYL",
{{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[]}}},
[]},
undefined,0,32768,
#Fun<rabbit_variable_queue.2.95522769>,
#Fun<rabbit_variable_queue.3.95522769>,
{0,nil},
{0,nil},
[],[]},
{undefined,
{client_msstate,msg_store_transient,
<<190,153,122,22,186,127,25,5,168,81,229,140,5,
142,73,73>>,
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[]}}},
{state,438349,
"/paytm/rabbitmq/mnesia/rabbit#pgperf-rabbitmq2/msg_store_transient"},
rabbit_msg_store_ets_index,
"/paytm/rabbitmq/mnesia/rabbit#pgperf-rabbitmq2/msg_store_transient",
<0.370.0>,442446,434242,446543,450640,
{2000,500}}},
false,0,4096,0,0,0,0,0,infinity,0,0,0,0,0,0,
{rates,0.0,0.0,0.0,0.0,-576459879667187727},
{0,nil},
{0,nil},
{0,nil},
{0,nil},
0,0,0,0,2048,default}},
undefined,undefined,
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}},
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}},
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}},
{state,
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[]}}},
delegate},
undefined}
** Reason for termination ==
** {bad_return_value,
{error,
{function_clause,
[{gm,check_membership,
[{20,<0.27470.0>},{error,not_found}],
[{file,"src/gm.erl"},{line,1590}]},
{gm,'-record_dead_member_in_group/5-fun-1-',4,
[{file,"src/gm.erl"},{line,1132}]},
{mnesia_tm,apply_fun,3,[{file,"mnesia_tm.erl"},{line,833}]},
{mnesia_tm,execute_transaction,5,
[{file,"mnesia_tm.erl"},{line,808}]},
{rabbit_misc,'-execute_mnesia_transaction/1-fun-0-',1,
[{file,"src/rabbit_misc.erl"},{line,537}]},
{worker_pool_worker,'-run/2-fun-0-',3,
[{file,"src/worker_pool_worker.erl"},{line,77}]}]}}}
=WARNING REPORT==== 7-Jul-2017::16:05:18 ===
Mnesia('rabbit#pgperf-rabbitmq2'): ** WARNING ** Mnesia is overloaded: {dump_log,write_threshold}
=ERROR REPORT==== 7-Jul-2017::16:47:39 ===
Channel error on connection <0.27776.0> (<rabbit#pgperf-rabbitmq2.1.27776.0>, vhost: '/', user: 'guest'), channel 1:
operation basic.get caused a channel exception not_found: "failed to perform operation on queue 'aliveness-test' in vhost '/' due to timeout"
=ERROR REPORT==== 7-Jul-2017::16:47:39 ===
webmachine error: path="/api/aliveness-test/%2F"
"Not Found"
=ERROR REPORT==== 7-Jul-2017::16:47:39 ===
Channel error on connection <0.10847.1> (<rabbit#pgperf-rabbitmq2.1.10847.1>, vhost: '/', user: 'guest'), channel 1:
operation queue.declare caused a channel exception not_found: "failed to perform operation on queue 'aliveness-test' in vhost '/' due to timeout"
=ERROR REPORT==== 7-Jul-2017::16:47:39 ===
Channel error on connection <0.151.1> (<rabbit#pgperf-rabbitmq2.1.151.1>, vhost: '/', user: 'guest'), channel 1:
operation queue.declare caused a channel exception not_found: "failed to perform operation on queue 'aliveness-test' in vhost '/' due to timeout"

RabbitMQ new consumer hangs

I'm using rabbitmq 3.6.6 using the docker image "rabbitmq:3"
Whenever I add a new consumer to my RabbitMQ queue it hangs from anywhere to 10 seconds 10 hours.
Below is an example of code used to get the error. I also get this error in Go. So it's not library dependant.
<?php
include(__DIR__."/vendor/autoload.php");
print "Start" . PHP_EOL;
$connection = new \PhpAmqpLib\Connection\AMQPStreamConnection('xxxx', 5697, 'guest', 'guest');
$channel = $connection->channel();
$callback = function($msg) {
echo " [x] Received ", $msg->body, "\n";
};
$channel->basic_consume('repositories', '', false, false, false, false, $callback);
while(count($channel->callbacks)) {
$channel->wait();
}
When I look at the logs I see
=INFO REPORT==== 31-Jan-2017::21:14:33 ===
accepting AMQP connection <0.891.0> (10.32.0.1:54216 -> 10.44.0.3:5672)
=INFO REPORT==== 31-Jan-2017::21:14:34 ===
accepting AMQP connection <0.902.0> (10.32.0.1:54247 -> 10.44.0.3:5672)
When I do list_consumer during via rabbitmqctl I see the consumer in the list, yet no messages are processed by it.
It turns out I needed to set the Qos setting.
Some more information can be found at:
http://www.rabbitmq.com/consumer-prefetch.html
https://github.com/streadway/amqp/blob/master/channel.go#L576

RabbitMQ STOMP connection

I am working on a fun project which requires me to learn message queues and websockets. I am trying to connect browsers via websockets to an instance of rabbitmq using sockjs rather than pure websockets. On rabbit I have activated the plugins for stomp and web_stomp (web_stomp is required when using sockjs).
The problem I am running into is that while the call from the browser seems to be working properly because a very brief connection to Rabbit is made through the webstomp/stomp connection but after 2 or 3 seconds the connection is dropped by Rabbit.
This is confirmed by the rabbitmq logs:
=INFO REPORT==== 11-Jul-2016::23:01:54 ===
accepting STOMP connection (192.168.1.10:49746 -> 192.168.1.100:55674)
=INFO REPORT==== 11-Jul-2016::23:02:02 ===
closing STOMP connection (192.168.1.10:49746 -> 192.168.1.100:55674)
This is the browser code that connects to RabbitMQ via the webstomp plugin:
var url = "http://192.168.1.100:55674/stomp";
var ws = new SockJS(url);
var client = Stomp.over(ws);
var header = {
login: 'test',
passcode: 'test'
};
client.connect(header,
function(){
console.log('Hooray! Connected');
},
function(error){
console.log('Error connecting to WS via stomp:' + JSON.stringify(error));
}
);
Here is the Rabbit config:
[
{rabbitmq_stomp, [{default_user, [{login, "test"},
{passcode, "test"}
]
},
{tcp_listeners, [{"192.168.1.100", 55674}]},
{heartbeat, 0}
]
}
]
I have been over the Rabbit docs a million times but this feels like something simple that I am overlooking.
Resolved. After combing through the logs I realized that web_stomp was listening on port 15674 so I changed the config file to reflect that. I swear I had made that change at some point but it did not seem to make a difference.
One of the late changes I made before sending out my request was to turn off heartbeat. Everything I have read states that sockjs does not support heartbeat and that there were suggestions to turn it off rather than use the default. In addition to turning off heartbeat in the config file I also added this to the browser code:
client.heartbeat.outgoing=0;
client.heartbeat.incoming=0;

RabbitMQ Consumer fails while receiving a MQTT message

I'm trying to publish a MQTT message and receive the message with an AMQP consumer by using the RabbitMQ-MQTT plugin on Ubuntu14.04. I'm publishing the MQTT message with the Mosquitto-clients package. I enabled the MQTT plugin for RabbitMQ.
Now if I want to send a MQTT message, my AMQP consumer code throws an exception:
Traceback (most recent call last):
File "consume_topic.py", line 33, in <module>
channel.start_consuming()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 722, in start_consuming
self.connection.process_data_events()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 88, in process_data_events
if self._handle_read():
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 184, in _handle_read
super(BlockingConnection, self)._handle_read()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 308, in _handle_read
self._on_data_available(data)
File "/usr/local/lib/python2.7/dist-packages/pika/connection.py", line 1134, in _on_data_available
consumed_count, frame_value = self._read_frame()
File "/usr/local/lib/python2.7/dist-packages/pika/connection.py", line 1201, in _read_frame
return frame.decode_frame(self._frame_buffer)
File "/usr/local/lib/python2.7/dist-packages/pika/frame.py", line 254, in decode_frame
out = properties.decode(frame_data[12:])
File "/usr/local/lib/python2.7/dist-packages/pika/spec.py", line 2479, in decode
(self.headers, offset) = data.decode_table(encoded, offset)
File "/usr/local/lib/python2.7/dist-packages/pika/data.py", line 106, in decode_table
value, offset = decode_value(encoded, offset)
File "/usr/local/lib/python2.7/dist-packages/pika/data.py", line 174, in decode_value
raise exceptions.InvalidFieldTypeException(kind)
pika.exceptions.InvalidFieldTypeException: b
My Pika (python) consumer code is the following:
#!/usr/bin/env python
import pika
import sys
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='logs',type='topic',durable=False)
result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue
binding_keys = sys.argv[1:]
if not binding_keys:
print >> sys.stderr, "Usage: %s [binding_key]..." % (sys.argv[0],)
sys.exit(1)
for binding_key in binding_keys:
channel.queue_bind(exchange='logs',
queue=queue_name,
routing_key=binding_key)
print ' [*] Waiting for logs. To exit press CTRL+C'
def callback(ch, method, properties, body):
print " [x] %r:%r" % (method.routing_key, body,)
channel.basic_consume(callback,
queue=queue_name,
no_ack=True)
channel.start_consuming()
My RabbitMQ configuration file is the following:
[{rabbit, [{tcp_listeners, [5672]}]},
{rabbitmq_mqtt, [{default_user, <<"guest">>},
{default_pass, <<"guest">>},
{allow_anonymous, true},
{vhost, <<"/">>},
{exchange, <<"logs">>},
{subscription_ttl, 1800000},
{prefetch, 10},
{ssl_listeners, []},
%% Default MQTT with TLS port is 8883
%% {ssl_listeners, [8883]}
{tcp_listeners, [1883]},
{tcp_listen_options, [binary,
{packet, raw},
{reuseaddr, true},
{backlog, 128},
{nodelay, true}]}]}
].
The log file shows the following:
=INFO REPORT==== 14-Apr-2015::10:57:50 ===
accepting AMQP connection <0.1174.0> (127.0.0.1:42447 -> 127.0.0.1:5672)
=INFO REPORT==== 14-Apr-2015::10:58:30 ===
accepting MQTT connection <0.1232.0> (127.0.0.1:53581 -> 127.0.0.1:1883)
=WARNING REPORT==== 14-Apr-2015::10:58:30 ===
closing AMQP connection <0.1174.0> (127.0.0.1:42447 -> 127.0.0.1:5672):
connection_closed_abruptly
=INFO REPORT==== 14-Apr-2015::10:58:30 ===
closing MQTT connection <0.1232.0> (127.0.0.1:53581 -> 127.0.0.1:1883)
Can anybody please help me? I googled the "pika.exceptions.IvalidFieldTypeException" and found that I'm not using a correct "Field Type", how is that?
This is most likely a bug in the specifications (decoder) for pika. I would recommend that you change library to something more frequently updated. As an example you could look at the author of pika's new library RabbitPy or my very own pika inspired library AMQP-Storm.
Although, it could also be that you are running a very old version of Pika. I found this commit from gmr that should have fixed your issue. You could try to upgrade to pika 0.9.14.