我想从某个日期从服务总线读取消息,但我的代码不阅读消息.在服务总线有任何选项,如设置触发器,我已经尝试了下面的代码从微软文档,但仍然无法接收消息.
消息处理程序
public static async Task<int> Main(string[] args)
{
await AdditionAsync();
return 0;
}
static async Task MessageHandler(ProcessMessageEventArgs args)
{
var body = args.Message.Body.ToString();
Console.WriteLine(body);
if (body.Contains("My Label"))
{
Console.WriteLine($"Received: {body} from subscription: <TOPIC-SUBSCRIPTION-NAME>");
}
}
错误处理程序
static Task ErrorHandler(ProcessErrorEventArgs args)
{
Console.WriteLine(args.Exception.ToString());
return Task.CompletedTask;
}
private static async Task AdditionAsync()
{
var clientOptions = new ServiceBusClientOptions
{
TransportType = ServiceBusTransportType.AmqpWebSockets
};
var client = new ServiceBusClient(
"Connection string",
clientOptions);
var test = new ServiceBusProcessorOptions()
{
}
var processor = client.CreateProcessor("TOpic", "subscription", new ServiceBusProcessorOptions());
try
{
processor.ProcessMessageAsync += MessageHandler;
processor.ProcessErrorAsync += ErrorHandler;
await processor.StartProcessingAsync();
Console.WriteLine("Wait for a minute and then press any key to end the processing");
Console.ReadKey();
Console.WriteLine("\nStopping the receiver...");
await processor.StopProcessingAsync();
Console.WriteLine("Stopped receiving messages");
}
finally
{
await processor.DisposeAsync();
await client.DisposeAsync();
}
Console.WriteLine("DONE");
Console.ReadLine();
}
}
我们能不能换个密码,在特定的日期收到信息。
1条答案
按热度按时间62o28rlo1#
在Azure门户中创建了一个服务总线现在转到资源并转到需要发送消息的服务总线资源管理器。在此之前,在服务总线中创建一个订阅,然后按如下所示发送消息。
现在要在特定日期检索消息,请使用以下代码
通过替换连接字符串、订阅名称和主题名称来运行上面的代码。我在我的环境中做了同样的事情,并在所需的日期获得了消息。