Cannot determine whether a queue with the specified format name exists.

Sometime back I had blogged about how to send messages to remote private queues. There were a few queries on how to read from remote queue as well.

To me it should have worked by using the MessageQueue.Receive API instead of .Send. I decided to give this a try anyway and it indeed is as trivial as that. However a few things to take care while trying to get this working.

1. Check the documentation to see where all the API works. The API may have limitations in working in workgroup mode if you are not using the direct format name syntax.

2. The other very important aspect is setting the formatter prior to receiving the message. You need to set this appropriately to binary or XML and specific type to ensure successful read.

To show a complete example, find below code that posts to the remote queue (transactional as well as non-transactional) and also reads from them. To keep things simple, I have used a simple string message here. However you can definitely use more complex types and custom types for sending and receiving (as long as they match both ways).

        private void btnPostToQueue_Click(object sender, EventArgs e)

        {

            //post to regular non-transactional remote queue using OS name

            MessageQueue rmQ =new MessageQueue("FormatName:Direct=OS:punhjw30076\\private$\\remote");

            rmQ.Send("sent to regular queue - Atul");

 

            //post to  transactional remote queue using IP address

            MessageQueue rmTxnQ =new MessageQueue("FormatName:Direct=TCP:100.100.100.12\\private$\\remoteTxn");

            rmTxnQ.Send("sent to transacted queue - Atul",MessageQueueTransactionType.Single);

        }

 

        private void btnGetFromQueue_Click(object sender, EventArgs e)

        {

            //retrieve from regular non-transactional remote queue using OS name

            MessageQueue rmQ =new MessageQueue("FormatName:Direct=OS:punhjw30076\\private$\\remote");

            rmQ.Formatter = newXmlMessageFormatter(newType[] { typeof(string) });

            System.Messaging.Message msg = rmQ.Receive();

            MessageBox.Show(msg.Body.ToString());

 

            //retrieve from transactional remote queue using IP address

            MessageQueue rmTxnQ =new MessageQueue("FormatName:Direct=TCP:100.100.100.12\\private$\\remoteTxn");

            rmTxnQ.Formatter = newXmlMessageFormatter(newType[] { typeof(string) });

            System.Messaging.Message msgTxn = rmTxnQ.Receive(MessageQueueTransactionType.Single);

            MessageBox.Show(msgTxn.Body.ToString());

        }

在调用远程的msmq是一定不要调用 MessageQueue.Exists(path) 、 mq = MessageQueue.Create(path, false);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值