简体   繁体   English

如何实现MSMQ触发器

[英]How to implement MSMQ Triggers

Do anybody can solve my problem? 有人可以解决我的问题吗?

I wanna fire one event when some data is inserted in MSMQ queue how i can do it? 我想在MSMQ队列中插入一些数据时触发一个事件我该怎么办?

You create your instance of the message queue and start peeking at it asynchronously: 您创建消息队列的实例并开始异步查看它:

MessageQueue queue = new MessageQueue( @".\PRIVATE$\Queue" );
queue.BeginPeek( TimeSpan.Infinite, null, OnMessageAdded);

The registered callback is called when a message was added to the queue. 将消息添加到队列时,将调用已注册的回调。 As far as you did not explain what your real problem is, I assume you want to get informed about new messages added to the queue: 至于你没有解释你真正的问题是什么,我假设你想知道添加到队列中的新消息:

private void OnMessageAdded( IAsyncResult ar )
{
    Message peekedMessage = queue.EndPeek(ar);
    //Do whatever you want. Raise a new event, process the message, ...
}

The message is not taken off the queue. 消息不会从队列中删除。 You can use the message, but it still remains in the queue. 您可以使用该消息,但它仍然保留在队列中。 So if you don't need the Message, you can simply call queue.EndPeek(ar); 所以如果你不需要Message,你可以简单地调用queue.EndPeek(ar); without using the result. 没有使用结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM