我正在使用 azure 服务总线主题作为我的解决方案的消息代理。根据我对每个订阅的理解,Azure 消息总线保留一个虚拟队列,因此在接收端消息的顺序不应受到干扰。
但实际上它有点不同,在我的场景中
- 输入大概是每两秒之后,(时间戳是正确的我已经验证过了)
- 如果我断开接收器一段时间,消息开始在 Azure 上针对订阅排队。
- 然后如果我再次连接接收器,接收代码接收消息很快,但没有保持顺序?
- 但是,如果我保持客户端连接,则按顺序接收消息(两秒后有 1 条消息)
接收代码
SubscriptionClient Client = SubscriptionClient.CreateFromConnectionString(connectionString, topicname, subscription_name);
// Configure the callback options.
OnMessageOptions options = new OnMessageOptions();
options.AutoComplete = false;
options.AutoRenewTimeout = TimeSpan.FromMinutes(1);
// Callback to handle received messages.
Client.OnMessage((message) =>
{
try
{
// Process message from queue.
string payload = message.GetBody<string>();
var myData = JsonConvert.DeserializeObject<MyData>(payload);
if(myData != null)
{
//Timestamp is not in order, when I connect after few minutes
Debug.WriteLine("SBC ==> " + myData.Timestamp);
}
// Remove message from queue.
message.Complete();
}
catch (Exception)
{
// Indicates a problem, unlock message in queue.
message.Abandon();
}
}, options);
输出
SBC ==> 5/23/2017 1:06:43 PM
SBC ==> 5/23/2017 1:06:45 PM
SBC ==> 5/23/2017 1:07:23 PM
SBC ==> 5/23/2017 1:07:19 PM
SBC ==> 5/23/2017 1:07:27 PM
SBC ==> 5/23/2017 1:07:07 PM
SBC ==> 5/23/2017 1:06:49 PM
SBC ==> 5/23/2017 1:07:47 PM
SBC ==> 5/23/2017 1:06:47 PM
SBC ==> 5/23/2017 1:08:03 PM
SBC ==> 5/23/2017 1:06:55 PM
SBC ==> 5/23/2017 1:06:51 PM
SBC ==> 5/23/2017 1:07:03 PM
SBC ==> 5/23/2017 1:07:51 PM
SBC ==> 5/23/2017 1:06:57 PM
SBC ==> 5/23/2017 1:07:05 PM
SBC ==> 5/23/2017 1:07:39 PM
SBC ==> 5/23/2017 1:07:43 PM
SBC ==> 5/23/2017 1:06:59 PM
SBC ==> 5/23/2017 1:07:09 PM
SBC ==> 5/23/2017 1:06:53 PM
SBC ==> 5/23/2017 1:07:33 PM
SBC ==> 5/23/2017 1:07:25 PM
SBC ==> 5/23/2017 1:07:57 PM
SBC ==> 5/23/2017 1:08:13 PM
任何人都可以解释为什么会这样吗?这对我来说有点混乱?