• 1,EasyNetQ-链接到RabbitMQ


    一、链接到RabbitMQ

    1,创建连接

    注意不能有空格

    var bus = RabbitHutch.CreateBus(“host=myServer;virtualHost=myVirtualHost;username=mike;password=topsecret”);

    1)host(必填):

    例如:host=localhost或者host=192.168.2.56或者host=myhost.mydomain.com

    使用标准格式主机:端口(host=myhost.com:5673)

    如果省略端口号,默认端口使用AMQP(5672)

    连接到RabbitMQ集群,每个集群节点指定以逗号分隔(host=myhost1.com,myhost2.com,myhost3.com)

    2)virtualHost(默认‘/’):

    例如:virtualHost=myVirtualHost

    3)username(默认guest):

    例如:username=mike

    4) password(默认guest):

    例如:password=mysecret

    5)requestedheartbeat(默认值是10秒):

    例如:requestedHeartbeat=10。设置为0,没有心跳。

    6) prefetchcount(默认值是50):

    例如:prefetchcount=1。这是由EasyNetQ发送ack之前由RabbitMQ发送的消息数。 设置为0用于无限预取(不推荐)。 设置为1,在消费者农场之间进行公平的工作平衡。

     7)publisherConfirms(默认为false):

    例如:publisherConfirms=true,这打开了Publisher Confirms.。

    8) persistentMessages(默认为true): 

    例如:persistentMessages=false。这决定了在发布消息时如何设置basic.properties中的delivery_mode。 false = 1,true = 2。 当设置为true时,消息将由RabbitMQ持久存储到磁盘,并在服务器重新启动后生存。 当设置为false时,可以预期性能提升。

    9) product(默认值是实例化总线的可执行文件的名称):

    例如:product=My really important service。在EasyNetQ 0.27.3中引入。 此处输入的值将显示在RabbitMQ的管理界面中。

    10) platform( 默认值是运行客户端进程实例化总线的机器的主机名):

    例如platform = my.fully.qualified.domain.name。在EasyNetQ 0.27.3中引入。 此处输入的值将显示在RabbitMQ的管理界面中。

    11)timeout(默认为10秒):

    例如timeout = 60。 在EasyNetQ 0.17中推出。 解析为System.UInt16。 范围从0到65535.格式为秒。 对于无限超时,请使用0。超出值时抛出System.TimeoutException。

    2,关闭连接

    bus.Dispose();

    这将关闭EasyNetQ使用的连接,渠道,消费者和所有其他资源。

    二、连接SSL

    var connection = new ConnectionConfiguration();
    
    connection.Port = 443;
    connection.UserName = "user";
    connection.Password = "pass";
    connection.Product = "SSLTest";
    
    var host1 = new HostConfiguration();
    host1.Host = "rmq1.contoso.com";
    host1.Port = 443;
    host1.Ssl.Enabled = true;
    host1.Ssl.ServerName = "rmq1.contoso.com";
    host1.Ssl.CertPath = "c:\tmp\myclient.p12";
    host1.Ssl.CertPassphrase = "secret";
    
    var host2 = new HostConfiguration();
    host2.Host = "rmq2.contoso.com";
    host2.Port = 443;
    host2.Ssl.Enabled = true;
    host2.Ssl.ServerName = "rmq2.contoso.com";
    host2.Ssl.CertPath = "c:\tmp\myclient.p12";
    host2.Ssl.CertPassphrase = "secret";
    
    connection.Hosts = new List<HostConfiguration> { host1, host2 };
    
    connection.Validate();        //非常重要
    
    var Bus = RabbitHutch.CreateBus(connection, services => services.Register<IEasyNetQLogger>(logger => new DoNothingLogger()));
  • 相关阅读:
    Eclipse 3.6 中安装WindowBuilder Pro及使用SWT Designer
    BEC听力训练 方法
    在Eclipse安装Aptana插件
    failed to create JVM 解决办法
    BEC听力训练 方法2
    ATF/Installing
    Eclipse中如何配置SWT
    语音信号 :lms算法麦克风语音降噪
    图像信号 matlab滤波器设计1 :高通滤波器应用和设计
    matlab m文件
  • 原文地址:https://www.cnblogs.com/zd1994/p/7161218.html
Copyright © 2020-2023  润新知