zoukankan      html  css  js  c++  java
  • c# ActiveMQ的使用

    /// <sumary>
    /// 接收方
    /// </sumary>
    public
    void StartClient() {
      var factory = new NMSConnectionFactory(new Uri("activemq:failover:(tcp://localhost:61616/?wireFormat.maxInactivityDuration=0)"));
      var connection = factory.CreateConnection();
      //ClientId:指定一个唯一值,可接收连线前服务端分配的消息
      connection.ClientId = "XXX";
      connection.ExceptionListener += Connection_ExceptionListener;
      connection.ConnectionInterruptedListener += Connection_ConnectionInterruptedListener;
      connection.ConnectionResumedListener += Connection_ConnectionResumedListener;
      connection.Start();
      var session = connection.CreateSession();
      //Queue,队列模式,队列中哪个接收方先接收到,其他接收方将不再接收,consumer.prefetchSize=1表示每次只接收一条消息
      consumer = session.CreateConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("MyMQQueueName" + "?consumer.prefetchSize=1"));
      consumer.Listener += new MessageListener(consumer_Listener);
    }

    /// <sumary>
    /// 接收到的消息
    /// </summary>
    void consumer_Listener(IMessage message)
    {
      string txt = HttpUtility.UrlDecode((ITextMessage)message.Text);
    }

  • 相关阅读:
    9、spring五种scope
    2、数据库四种事务隔离级别
    4、jquery获取servlet值
    3、$.post不执行
    A brief Arch installation in VMware
    Git经验记录
    Windows上virtualenv搭建python开发环境
    no such file django-admin.py
    复制拷贝函数+重载operator=
    Reconfigure CentOS+freeradius+daloradius again
  • 原文地址:https://www.cnblogs.com/RedSky/p/12882220.html
Copyright © 2011-2022 走看看