zoukankan      html  css  js  c++  java
  • 【EasyNetQ】- 发布确认

    默认的AMQP发布不是事务性的,并不保证您的消息实际到达代理。AMQP确实指定了事务发布,但是使用RabbitMQ它非常慢,我们还没有通过EasyNetQ API支持它。对于高性能保证交付,建议您使用“发布者确认”。简单来说,这是AMQP的扩展,它在代理成功接收到您的消息时提供回调。

    “成功收到”是什么意思?这取决于 ...

    • 瞬时消息在入队时确认。
    • 只要持久性消息持久保存到磁盘,或者在每个队列上消耗持久消息,就会确认该消息。
    • 直接确认不可路由的瞬态消息并将其发布。

    有关发布者确认的更多信息,请阅读RabbitMQ博客上的公告

    通过在连接字符串上设置publisherConfirms = true来启用发布者确认:

    bus = RabbitHutch.CreateBus("host=localhost;publisherConfirms=true;timeout=10");

    同步bus.Publish(..)方法将在返回之前等待确认。在超时期限之前未确认(也在连接字符串中配置)将导致抛出异常。随着发布者确认同步发布方法将显着减慢。如果需要考虑性能,则应考虑使用PublishAsync方法:

    bus.PublishAsync(new MyMessage
        {
            Text = "Hello World"
        }).ContinueWith(task =>
            {
                // this only checks that the task finished
                // IsCompleted will be true even for tasks in a faulted state
                // we use if (task.IsCompleted && !task.IsFaulted) to check for success
                if (task.IsCompleted) 
                {
                    //Console.Out.WriteLine("{0} Completed", count);
                }
                if (task.IsFaulted)
                {
                    Console.Out.WriteLine("
    
    ");
                    Console.Out.WriteLine(task.Exception);
                    Console.Out.WriteLine("
    
    ");
                }
            });

    这将在收到确认之前返回。如果未收到确认或NACK确认,则任务将在故障状态下完成。

  • 相关阅读:
    【原】webpack--loaders,主要解释为什么需要loaders和注意事项
    【原】通过npm script运行webpack的原理
    原生js深拷贝函数
    git add 添加错文件的撤销方法
    item2 快捷键
    sudo su 和sudo -s的区别
    nvm常用命令
    【雅思】【口语】Describe a product you bought and felt happy
    【雅思】【口语】Help others
    【雅思】【口语】
  • 原文地址:https://www.cnblogs.com/wangwust/p/9437456.html
Copyright © 2011-2022 走看看