消耗MSMQ的2台机器可以复制消息吗? [英] 2 machines consuming MSMQ can duplicate messages ?

查看:65
本文介绍了消耗MSMQ的2台机器可以复制消息吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




基本上,我使用的是.Net MessageQueue类,我将一个带有FileName的消息发送到一个队列,但是我收到了很多来自机器的错误使用文件不存在或FileNotFoundException之类的队列。机器应该删除文件。



如果有人熟悉此代码:



Hi
Basically, I'm using the class of .Net MessageQueue, I send a Message with FileName to a Queue, but I've received many errors from the Machines that consume the Queue like "File doesn't exist" or "FileNotFoundException". The machines supposed to delete the files.

If someone familiar with this code:

static void Main()
{
   for (int i = 0; i < 10; i++)
       ThreadPool.QueueUserWorkItem(new WaitCallback(ListenerMessage));
}

private void ListenerMessage(object o)
{
MessageQueue queueSouce = new MessageQueue("otherMachine\otherQueue");
queueSouce.Formatter = new XmlMessageFormatter(new Type[] { typeof(XmlDocument) });

queueSouce.ReceiveCompleted += new ReceiveCompletedEventHandler(queueSouce_ReceiveCompleted);
queueSouce.BeginReceive();
}

void queueSouce_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
{
 ...
}





我在这里的理论是我用的很多与MessageQueue连接的许多机器中的线程开始复制我的消息,当两台计算机收到相同的消息时,其中一台将抛出文件正由另一个进程使用或找不到文件等异常



有人可以帮帮我吗?



My theory in here is I'm using many threads in many machines connected with MessageQueue that start duplicate my messages, and when two computers receive the same message one of them will throw a exception that "file is using by another process" or "the file not found", etc

Someone can help me ?

推荐答案

想象一个线程已经完成而另一个线程没有,所以线程一,之后endReceive,当第二个线程有一个文件名没有指向文件的消息队列时,将删除该文件,因为第一个线程删除了该文件。
Imagine one thread is completed and another thread is not, so thread one, after endReceive , will delete the file when second thread have a message queue with a file name which doesn't point to a file, because first thread delete that.


这篇关于消耗MSMQ的2台机器可以复制消息吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆