以下是我的Azure Service Fabric Service Bus队列侦听器的确切代码。 我遇到的问题是_client.OnMessageAsync“休息”时不使用几分钟。它最终会在5分钟内唤醒并处理排队的消息。消息永远不会丢失或死亡,但这是不可接受的行为。我试过调整消息选项,但是nada ..
有什么想法吗?
internal sealed class Core : StatelessService
{
readonly QueueClient _client;
readonly OnMessageOptions _msgOptions;
public Core(StatelessServiceContext context)
: base(context)
{
var connectionString = CloudConfigurationManager.GetSetting(Resources.ServiceBusConnectionString);
var inQueue = CloudConfigurationManager.GetSetting(Resources.InQueue);
var factory = MessagingFactory.CreateFromConnectionString(connectionString);
_client = factory.CreateQueueClient(inQueue, ReceiveMode.PeekLock);
_msgOptions = new OnMessageOptions
{
AutoComplete = false,
MaxConcurrentCalls = 5
};
}
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[0];
}
protected override async Task RunAsync(CancellationToken cancellationToken)
{
await Task.Run(() =>
_client.OnMessageAsync(
async message =>
{
OnReceived(message);
await message.CompleteAsync();
}, _msgOptions),
cancellationToken);
}
private void OnReceived(BrokeredMessage brokeredMessage)
{
var message = brokeredMessage.GetBody<Message>();
ServiceEventSource.Current.ServiceMessage(Context, "Working-{0}", message.Transaction.Id);
var preocessor = new Processor();
preocessor.Process(message);
}
}