Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#EasyNetQ中的许多onMessage操作_C#_Rabbitmq_Easynetq - Fatal编程技术网

C#EasyNetQ中的许多onMessage操作

C#EasyNetQ中的许多onMessage操作,c#,rabbitmq,easynetq,C#,Rabbitmq,Easynetq,我有个问题。我有一个简单的方法,它创建对RabbitMQ总线的订阅并从中读取消息,然后触发适当的onMessage操作处理程序,它看起来如下所示: this.bus = RabbitHutch.CreateBus("host=localhost;timeout=999;virtualHost=/;username=guest;password=guest"); void timer1_Tick(object sender, EventArgs e) { C

我有个问题。我有一个简单的方法,它创建对RabbitMQ总线的订阅并从中读取消息,然后触发适当的onMessage操作处理程序,它看起来如下所示:

    this.bus = RabbitHutch.CreateBus("host=localhost;timeout=999;virtualHost=/;username=guest;password=guest");

    void timer1_Tick(object sender, EventArgs e)
    {
       Console.WriteLine($"{DateTime.Now}");
    }

    var subscribeId = "QueueId";
    var running = false;
    var handler = new Action<ResponseMessage>(response =>
    {
        switch (response.Op)
        {
            case "Start":
                timer.AutoReset = true; 
                timer.Elapsed += timer1_Tick;
                timer.Start();
                break;
            default: Console.WriteLine("Default");
                break;
        }
    });

    this.bus.Subscribe<ResponseMessage>(cabinetSubscribeId, handler, sub => sub.WithTopic(cabinetSubscribeId));
this.bus=RabbitHutch.CreateBus(“host=localhost;timeout=999;virtualHost=/;username=guest;password=guest”);
无效计时器1_刻度(对象发送方,事件参数e)
{
WriteLine($“{DateTime.Now}”);
}
var subscriptbeid=“QueueId”;
var running=false;
变量处理程序=新操作(响应=>
{
开关(response.Op)
{
案例“开始”:
timer.AutoReset=true;
timer.appead+=计时器1_刻度;
timer.Start();
打破
默认:Console.WriteLine(“默认”);
打破
}
});
this.bus.Subscribe(cabinetSubscribeId,handler,sub=>sub.WithTopic(cabinetSubscribeId));
当接收到一条消息时,它可以正常工作,但是如果另一条消息带有Op值start(这可能会发生),我有两个处理程序彼此相邻运行,它们将随着每个传入的start消息而递增


是否可以停止以前的onMessage处理程序,或将它们仅限制为1?

每次消息到达时,执行以下操作:

 case "Start":
                timer.AutoReset = true; 
                timer.Elapsed += timer1_Tick;
                timer.Start();
                break;
您可以创建对计时器的附加订阅。所以定时器现在将调用time\u click1两次。 现在还不清楚为什么您需要一个计时器,但是如果您需要,那么您首先需要取消订阅上一个计时器,它也应该是thread sage,所以在这段代码周围放置lock statation

 case "Start":
                timer.AutoReset = true; 
                timer.Elapsed -= timer1_Tick;
                timer.Elapsed += timer1_Tick;
                timer.Start();