gpt4 book ai didi

c# - 未收到 Azure 服务总线消息

转载 作者:行者123 更新时间:2023-11-30 12:30:56 24 4
gpt4 key购买 nike

我正在从 Web 角色向辅助角色发送消息。早些时候,这些消息被正确且立即地接收到,但是现在,尽管所有消息的内容都相同,但现在却突然没有收到某些消息。就像如果我现在发送一条消息,它没有收到,但之后如果我发送另一条消息,则会收到最新的一条消息。之前没有收到的消息会在几秒钟后突然收到,或者有时会因为生存时间已过期而变成死信消息。

我无法弄清楚问题出在哪里,有什么想法吗?或者这种行为对于服务总线来说是正常的吗?

这就是我以 worker 角色接收消息的方式

编辑:

public override void Run()
{
while (!IsStopped)
{
try
{
if (BroadcastReceived)
{
BroadcastReceived = false;
// Receive the message from Web Role to upload the broadcast to queue
BroadcastClient.BeginReceive(OnWebRoleMessageReceived, null);
}

if (SignalRMessageReceived)
{
SignalRMessageReceived = false;
// Receive the message from SignalR BroadcastHub
SignalRClient.BeginReceive(OnSignalRMessageReceived, null);
}

if (SignalRFirstTimeMessageReceived)
{
SignalRFirstTimeMessageReceived = false;
// Receive the message from SignalR BroadcastHub
SignalRFirstTimeClient.BeginReceive(OnSignalRFirstTimeMessageReceived, null);
}
}
}


public void OnWebRoleMessageReceived(IAsyncResult iar)
{
BrokeredMessage receivedBroadcastMessage = null;
receivedBroadcastMessage = BroadcastClient.EndReceive(iar);

if (receivedBroadcastMessage != null)
{
// Process the message
receivedBroadcastMessage.Complete();
}
BroadcastReceived = true;
}

更新:

BroadcastClient = CloudStorageHelper.GetServiceBusQueueClient(Queuenames.ApiToWorkerRole);

public static QueueClient GetServiceBusQueueClient(string queuename)
{
string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");

var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

if (!namespaceManager.QueueExists(queuename))
{
namespaceManager.CreateQueue(queuename);
}

QueueClient Client = QueueClient.CreateFromConnectionString(connectionString, queuename);



return Client;
}

网络角色:

var queueClient = CloudStorageHelper.GetServiceBusQueueClient(Queuenames.ApiToWorkerRole);

//for testing purposes
record.Username = "owner";
record.Channel = "World";
record.Title = "Sample";
record.Duration = 10;

BrokeredMessage message = new BrokeredMessage(record);

queueClient.Send(message);

最佳答案

出现此问题是因为在我们的辅助角色中,我们不断检查服务总线队列以查看消息是否已到达。当我们同时启动本地和云工作角色时,这两个工作角色都会尝试从同一服务总线队列接收新消息。因此,有时云端接受它,有时本地接受。

对云和本地项目使用不同的服务总线队列名称解决了该问题。

关于c# - 未收到 Azure 服务总线消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14999527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com