[rabbitmq-discuss] SocketException when invoking model.BasicPublish
Scott McFadden
scott.kendall.mcfadden at gmail.com
Fri Jun 20 16:27:28 BST 2014
Hi Michael, had to decompile RabbitMQ.Client assembly and step through to
find the issue. Apparently, my code doesn't always pass a non-null
messageId. Setting a null messageId on the basicproperties is allowed but
the writing of a null messageId on the wire will cause an error inside
of RabbitMQ.Client. So moral of the story is don't ever set a
basicproperties property unless it's non null (at least as of
RabbitMQ.Client 3.3.0).
I put connection and channel logic back in the same method and it works
great. Here is new working version.
private void PublishMessage(byte[] message, Type messageType, string
contentType, string messageId)
{
if (message == null || message.Length == 0)
{
throw new ArgumentNullException("message");
}
if (messageType == null)
{
throw new ArgumentNullException("messageType");
}
if (String.IsNullOrEmpty(contentType))
{
throw new ArgumentNullException("contentType");
}
// if (String.IsNullOrEmpty(messageId))
// {
// throw new ArgumentNullException("messageId");
// }
var factory = new ConnectionFactory() {VirtualHost =
this.VirtualHost, HostName = this.Host, UserName = this.User, Password =
this.Password };
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
IBasicProperties props = channel.CreateBasicProperties();
props.SetPersistent(this.PersistMessages);
//Mime time
props.ContentType = contentType;
props.Type = messageType.FullName;
if (!String.IsNullOrEmpty(messageId))
{
//Must be careful not to set IBasicProperties with
possible null value as this will cause serialization errors downstream
(RabbitMQ.Client 3.3.0)
props.MessageId = messageId;
}
//Note, may get AlreadyClosedException here if publishing
to a incorrect exchange name
channel.BasicPublish(this.ExchangeName, this.RoutingKey,
props, message);
}
}
thanks for the help.
scott
On Wed, Jun 18, 2014 at 10:05 PM, Michael Klishin <mklishin at gopivotal.com>
wrote:
> On 19 June 2014 at 07:02:17, Scott McFadden (
> scott.kendall.mcfadden at gmail.com) wrote:
> > > It makes me think I screwed up the server side configuration
> > when reinstalling.
>
> There is no configuration that can affect framing/frame interleaving in
> the client.
> This is also the kind of issues that we'd see reported constantly if it
> was a client
> issue. Finally, it happens on a brand new connection.
>
> I'd recommend doing two things:
>
> * Running a tracer proxy in front of RabbitMQ [1] to see what's being
> sent on the wire
> * Open a connection on app start if you can instead of opening a new one
> per channel
>
> If the latter does not change anything, please post the output of the
> tracer.
>
> 1. http://www.rabbitmq.com/java-tools.html, see Tracer
> --
> MK
>
> Software Engineer, Pivotal/RabbitMQ
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20140620/88e2af97/attachment.html>
More information about the rabbitmq-discuss
mailing list