[rabbitmq-discuss] Connection close forced

Emile Joubert emile at rabbitmq.com
Wed Nov 3 15:10:58 GMT 2010


Hi Adam,

On 03/11/10 13:51, Adam Kaminiecki wrote:
> Hi,
> 
> Im connecting to broker and before i going to send a message event occurs
> ConnectionShutdown  with  reason "Connection close forced" code=200
> 
> 
> my code:
> 
> var conFactory = new ConnectionFactory {Address = server};
>                 using (conn = conFactory.CreateConnection())
>                 {
>                     conn.AutoClose = false;
> 
>                     using (var channel = conn.CreateModel())
>                     {
>                         channel.BasicReturn += new
> RabbitMQ.Client.Events.BasicReturnEventHandler(channel_BasicReturn);
>                         if (channel.IsOpen)
>                         {
>                             channel.QueueDeclare(RmqQueue);
>                         }
> 
>                     }
>                 }
> here event occurs
> 
> after that I'm using
> byte[] messageBodyBytes = System.Text.Encoding.UTF8.GetBytes(message);
>                 if (channel.IsOpen)
>                 {
>                     channel.BasicPublish(RmqQueue, RmqQueue, null,
> messageBodyBytes);
>                 }
> 
> channel and connection is closed after QueueDeclare
> what I'm doing wrong?

The reason for the problem is that the connection and channel are both
scoped with using{}. Both have been disposed at the point where you try
to use them. The examples contain some illustrations of how to scope the
connection and channel correctly.

Regards

Emile



More information about the rabbitmq-discuss mailing list