What happens when multiple threads use the same channel to publish messages at the same time?

42 views
Skip to first unread message

ql...@mtu.edu

unread,
Aug 3, 2017, 12:25:35 AM8/3/17
to simpleamqpclient-users
Hello,

I want to publish different messages to different queue at the same time using multiple threads.
Do I need to create a new Channel for each thread?

Thank you

Alan Antonuk

unread,
Aug 3, 2017, 12:39:31 AM8/3/17
to ql...@mtu.edu, simpleamqpclient-users
A Channel object is not thread-safe.  In order to use it from multiple threads you must synchronize access to the Channel (e.g., use a mutex so that only 1 thread is accessing the Channel object at a time).

Depending on your use-case you may be able to get away with Channel (e.g., if you expect all threads to publish relatively few messages, and would have low contention when using the Channel), or you may be better off with a Channel per thread if you expect all threads to be publishing a lot of message concurrently.

-Alan

--
You received this message because you are subscribed to the Google Groups "simpleamqpclient-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-...@googlegroups.com.
To post to this group, send email to simpleamqpc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/simpleamqpclient-users/a42635ce-a7f5-48fd-bfc9-5e0d0a77a5d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages