我们有一个服务从n个消息队列接收消息.但是,如果重新启动消息队列服务,即使消息队列服务已成功重新启动,消息检索服务也会停止接收消息.
我试图专门捕获消息检索服务中抛出的MessageQueueException并再次调用队列的BeginReceive方法.但是,在消息队列服务重新启动的2秒左右,我得到大约1875个异常实例,然后当我们的StartListening方法中抛出另一个MessageQueueException时,服务停止运行.
有没有一种优雅的方法从消息队列服务重新启动恢复?
private void OnReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
{
MessageQueue queue = (MessageQueue)sender;
try
{
Message message = queue.EndReceive(e.AsyncResult);
this.StartListening(queue);
if (this.MessageReceived != null)
this.MessageReceived(this, new MessageReceivedEventArgs(message));
}
catch (MessageQueueException)
{
LogUtility.LogError(String.Format(CultureInfo.InvariantCulture, StringResource.LogMessage_QueueManager_MessageQueueException, queue.MachineName, queue.QueueName, queue.Path));
this.StartListening(queue);
}
}
public void StartListening(MessageQueue queue)
{
queue.BeginReceive();
}
Run Code Online (Sandbox Code Playgroud)
我需要处理这个导致的无限循环问题并清理一下但是你明白了.
发生MessageQueueException时,调用RecoverQueue方法.
private void RecoverQueue(MessageQueue queue)
{
string queuePath = queue.Path;
bool queueRecovered = false;
while (!queueRecovered)
{
try
{
this.StopListening(queue);
queue.Close();
queue.Dispose();
Thread.Sleep(2000);
MessageQueue newQueue = this.CreateQueue(queuePath);
newQueue.ReceiveCompleted += new ReceiveCompletedEventHandler(this.OnReceiveCompleted);
this.StartListening(newQueue); …Run Code Online (Sandbox Code Playgroud) 我取消了在私有队列上发送消息的权限,但MessageQueue.CanWrite从未返回false.我可以切换接收消息权限,CanRead属性按预期响应.为什么CanWrite财产会有不同的表现?
我已经与几个不同的AD用户测试了这个问题,结果是一样的.
是否有不同的方法来验证特定用户帐户是否可以将消息发送到特定的远程专用队列?
public class SendBehavior : IMsmqRuleBehavior
{
public bool Validate(string queuePath)
{
using (var queue = new MessageQueue(queuePath, QueueAccessMode.Send))
{
return queue.CanWrite;
}
}
}
public class ReceiveBehavior : IMsmqRuleBehavior
{
public bool Validate(string queuePath)
{
using (var queue = new MessageQueue(queuePath, QueueAccessMode.Receive))
{
return queue.CanRead;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我需要针对SQL Server 2012可用性组创建链接服务器,并且我希望将所有请求路由到只读副本.但是,我无法确定如何指定ReadOnly Application Intent以确保将请求路由到正确的副本.
有没有人以这种方式成功配置链接服务器?