显示服务总线的数据/消息

问题描述 投票:0回答:0

我想从某个日期读取来自服务总线的消息,但我的代码没有读取消息。 在服务总线中是否有设置触发器之类的选项, 我已经尝试了 Microsoft 文档中的以下代码,但仍然无法接收消息。

消息处理程序

 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();

    }
}

我们可以更改代码并在特定日期接收消息吗?

c# azure servicebus
© www.soinside.com 2019 - 2024. All rights reserved.