Esempio n. 1
0
        public void CachedMessageConsumer()
        {
            IConnectionFactory connectionFactory = CreateConnectionFactory();

            mocks.ReplayAll();


            CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();

            cachingConnectionFactory.TargetConnectionFactory = connectionFactory;
            IConnection con1 = cachingConnectionFactory.CreateConnection();

            ISession            sessionA    = con1.CreateSession(AcknowledgementMode.Transactional);
            IDestination        destination = new ActiveMQQueue("test.dest");
            IMessageConsumer    consumerA   = sessionA.CreateConsumer(destination);
            TestMessageConsumer tmpA        = GetTestMessageConsumer(consumerA);

            sessionA.Close();

            ISession            sessionB  = con1.CreateSession(AcknowledgementMode.Transactional);
            IMessageConsumer    consumerB = sessionB.CreateConsumer(destination);
            TestMessageConsumer tmpB      = GetTestMessageConsumer(consumerB);

            Assert.AreSame(tmpA, tmpB);
            mocks.VerifyAll();
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Console.WriteLine("sending message. Enter to exit.");
            //tạo connection factory
            IConnectionFactory factory = new
                                         ConnectionFactory("tcp://localhost:61616");
            //tạo connection
            IConnection con = factory.CreateConnection("admin", "admin");

            con.Start(); //nối tới MOM
                         //tạo session
            ISession session = con.CreateSession(AcknowledgementMode.AutoAcknowledge);
            //tạo producer
            ActiveMQQueue    destination = new ActiveMQQueue("thanthidet");
            IMessageProducer producer    = session.CreateProducer(destination);
            //send message
            //biến đối tượng thành XML document String
            patiens p = new patiens(long.Parse(txtMaBN.Text), txtCMND.Text, txtTenBN.Text, txtDiachi.Text);
            //string xml = genXML(p).ToLower();
            string xml = new XMLObjectConverter <patiens>().object2XML(p);

            Console.WriteLine(xml.ToLower());
            IMessage msg = new ActiveMQTextMessage("Hola mondo");

            producer.Send(msg);
            //shutdown
            session.Close();
            con.Close();
        }
Esempio n. 3
0
        /// <summary>
        /// 发送Queue队列消息   点对点
        /// </summary>
        /// <param name="queueName"></param>
        /// <param name="msg"></param>
        public static void SendQueueMessage(string queueName, string msg)
        {
            if (factory == null)
            {
                return;
            }

            //创建链接 Connection
            using (var connection = factory.CreateConnection())
            {
                connection.Start();
                //创建Session
                using (var session = connection.CreateSession())
                {
                    //创建提供者Producer
                    //using (var producer = session.CreateProducer(session.GetDestination(queueName, DestinationType.Queue)))
                    IDestination destination = new ActiveMQQueue(queueName);
                    using (var producer = session.CreateProducer(destination))
                    {
                        //持久化模式
                        producer.DeliveryMode = MsgDeliveryMode.Persistent;
                        //详细优先级
                        producer.Priority = MsgPriority.Normal;
                        //消息生存时间
                        producer.TimeToLive = TimeSpan.FromHours(1);
                        //发送消息
                        producer.Send(session.CreateTextMessage(msg));
                    }
                }
            }
        }
Esempio n. 4
0
        private void btnReceiver_Click(object sender, EventArgs e)
        {
            IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616");
            IConnection        con     = factory.CreateConnection("admin", "admin");

            con.Start();

            ISession      session     = con.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQQueue destination = new ActiveMQQueue("MyQueue");

            IMessageConsumer consumer = session.CreateConsumer(destination);
            IMessage         message  = consumer.Receive();

            if (message is ITextMessage)
            {
                ITextMessage         msg = message as ITextMessage;
                JavaScriptSerializer jss = new JavaScriptSerializer();
                SinhVien             sv  = jss.Deserialize <SinhVien>(msg.Text);
                txtName.Text = sv.Name;
            }
            else
            {
                Console.WriteLine("Unexpected message type: " + message.GetType().Name);
            }


            session.Close();
            con.Close();
        }
Esempio n. 5
0
        public bool SendEvent <TEntity>(TEntity model, string queueName)
        {
            bool succes = false;

            try
            {
                IObjectMessage objectMessage;


                ISession         session         = connection.CreateSession();
                ActiveMQQueue    queue           = new ActiveMQQueue(queueName);
                IMessageProducer messageProducer = session.CreateProducer();

                objectMessage = session.CreateObjectMessage(model);

                messageProducer.Send(queue, objectMessage);
                succes = true;
            }
            catch (Exception)
            {
                throw;
            }

            return(succes);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            Console.WriteLine("sending message. Enter to exit.");
            //tạo connection factory
            IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616");
            //tạo connection
            IConnection con = factory.CreateConnection("admin", "admin");

            con.Start(); //nối tới MOM
                         //tạo session
            ISession session = con.CreateSession(AcknowledgementMode.AutoAcknowledge);
            //tạo producer
            ActiveMQQueue    destination = new ActiveMQQueue("thanthidet");
            IMessageProducer producer    = session.CreateProducer(destination);
            //send message
            //biến đối tượng thành XML document String
            person p = new person(1001, "Truong Van COi", new DateTime());
            //string xml = genXML(p).ToLower();
            string xml = new XMLObjects <person>().object2XML(p);

            Console.WriteLine(xml.ToLower());
            IMessage msg  = new ActiveMQTextMessage("Hola mondo");
            IMessage msg1 = new ActiveMQTextMessage("Halo mondo");

            producer.Send(msg);
            producer.Send(msg1);
            //shutdown
            session.Close();
            con.Close();
            Console.ReadKey();
        }
Esempio n. 7
0
 /// <summary>
 /// 订阅 或者读取指定队列的消息 含有过滤条件 filter=key+val
 /// </summary>
 /// <param name="config"></param>
 /// <param name="clientId"></param>
 /// <param name="filter"></param>
 /// <param name="ac"></param>
 public static void SubscriberQuene(AQConfig config, string clientId, string filter, Action <MessageResult> ac = null)
 {
     if (!subQuene.ContainsKey(clientId))
     {
         var factory = new ConnectionFactory(config._AQConfigConnectString);
         var conn    = factory.CreateConnection();
         conn.ClientId = clientId;
         conn.Start();
         var session = conn.CreateSession();
         var queue   = new ActiveMQQueue(config.ActiveMQName);
         //通过会话创建一个消费者,这里就是Queue这种会话类型的监听参数设置
         IMessageConsumer consumer = session.CreateConsumer(queue, filter);
         if (ac != null)
         {
             consumer.Listener += new MessageListener((m) =>
             {
                 ac(new MessageResult()
                 {
                     custom   = clientId,
                     IMessage = m
                 });
             });
         }
         subQuene.Add(clientId, new SubTopic()
         {
             ConnectionFactory = factory,
             connection        = conn,
             session           = session
         });
     }
 }
Esempio n. 8
0
 /// <summary>
 /// 添加一条消息到队列中 含有条件key=val
 /// </summary>
 /// <param name="config"></param>
 /// <param name="textMsg"></param>
 /// <param name="key"></param>
 /// <param name="val"></param>
 public static void SendMessageToQuene(AQConfig config, string textMsg, string key, string val)
 {
     if (!string.IsNullOrEmpty(textMsg))
     {
         var factory = new ConnectionFactory(config._AQConfigConnectString);
         //创建连接
         using (var connection = factory.CreateConnection())
         {
             //创建一个会话
             using (ISession session = connection.CreateSession())
             {
                 //通过会话创建生产者,方法里面new出来的是MQ中的Queue
                 IDestination destination = new ActiveMQQueue(config.ActiveMQName);
                 //创建生产者
                 IMessageProducer producer = session.CreateProducer(destination);
                 //创建一个文本消息
                 var message = producer.CreateTextMessage(textMsg);
                 //给这个对象赋实际的消息
                 //message.Text = textMsg;
                 //设置消息对象的属性,这个很重要哦,是Queue的过滤条件,也是P2P消息的唯一指定属性
                 message.Properties.SetString(key, val);
                 //生产者把消息发送出去,几个枚举参数MsgDeliveryMode是否长链,MsgPriority消息优先级别,发送最小单位,
                 //当然还有其他重载
                 //发送消息
                 producer.Send(message, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue);
             }
         }
     }
 }
     public void TestFallbackToExclusiveConsumer() 
     {
         IConnection conn = createConnection(true);
 
         ISession exclusiveSession = null;
         ISession fallbackSession = null;
         ISession senderSession = null;
 
         try 
         {
             exclusiveSession = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
             fallbackSession = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
             senderSession = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
 
             // This creates the exclusive consumer first which avoids AMQ-1024
             // bug.
             ActiveMQQueue exclusiveQueue = new ActiveMQQueue("TEST.QUEUE4?consumer.exclusive=true");
             IMessageConsumer exclusiveConsumer = exclusiveSession.CreateConsumer(exclusiveQueue);
 
             ActiveMQQueue fallbackQueue = new ActiveMQQueue("TEST.QUEUE4");
             IMessageConsumer fallbackConsumer = fallbackSession.CreateConsumer(fallbackQueue);
 
             ActiveMQQueue senderQueue = new ActiveMQQueue("TEST.QUEUE4");
 
             IMessageProducer producer = senderSession.CreateProducer(senderQueue);
             producer.DeliveryMode = MsgDeliveryMode.NonPersistent;
 
             IMessage msg = senderSession.CreateTextMessage("test");
             producer.Send(msg);
             Thread.Sleep(500);
 
             // Verify exclusive consumer receives the message.
             Assert.IsNotNull(exclusiveConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
             Assert.IsNull(fallbackConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
 
             // Close the exclusive consumer to verify the non-exclusive consumer
             // takes over
             exclusiveConsumer.Close();
 
             producer.Send(msg);
 
             // Verify other non-exclusive consumer receices the message.
             Assert.IsNotNull(fallbackConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
 
             // Create exclusive consumer to determine if it will start receiving
             // the messages.
             exclusiveConsumer = exclusiveSession.CreateConsumer(exclusiveQueue);
 
             producer.Send(msg);
             Assert.IsNotNull(exclusiveConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
             Assert.IsNull(fallbackConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
         } 
         finally
         {
             fallbackSession.Close();
             senderSession.Close();
             conn.Close();
         }
     }
        //
        // Write the booleans that this object uses to a BooleanStream
        //
        public override int TightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs)
        {
            ActiveMQQueue info = (ActiveMQQueue)o;

            int rc = base.TightMarshal1(wireFormat, info, bs);

            return(rc + 0);
        }
Esempio n. 11
0
        public void TestFailoverToAnotherExclusiveConsumerCreatedFirst()
        {
            IConnection conn = createConnection(true);

            ISession exclusiveSession1 = null;
            ISession exclusiveSession2 = null;
            ISession fallbackSession   = null;
            ISession senderSession     = null;

            purgeQueue(conn, new ActiveMQQueue("TEST.QUEUE2"));

            try
            {
                exclusiveSession1 = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
                exclusiveSession2 = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
                fallbackSession   = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
                senderSession     = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);

                // This creates the exclusive consumer first which avoids AMQ-1024
                // bug.
                ActiveMQQueue    exclusiveQueue     = new ActiveMQQueue("TEST.QUEUE2?consumer.exclusive=true");
                IMessageConsumer exclusiveConsumer1 = exclusiveSession1.CreateConsumer(exclusiveQueue);
                IMessageConsumer exclusiveConsumer2 = exclusiveSession2.CreateConsumer(exclusiveQueue);

                ActiveMQQueue    fallbackQueue    = new ActiveMQQueue("TEST.QUEUE2");
                IMessageConsumer fallbackConsumer = fallbackSession.CreateConsumer(fallbackQueue);

                ActiveMQQueue senderQueue = new ActiveMQQueue("TEST.QUEUE2");

                IMessageProducer producer = senderSession.CreateProducer(senderQueue);
                producer.DeliveryMode = MsgDeliveryMode.NonPersistent;

                IMessage msg = senderSession.CreateTextMessage("test");
                producer.Send(msg);
                Thread.Sleep(500);

                // Verify exclusive consumer receives the message.
                Assert.IsNotNull(exclusiveConsumer1.Receive(TimeSpan.FromMilliseconds(1000)));
                Assert.IsNull(exclusiveConsumer2.Receive(TimeSpan.FromMilliseconds(1000)));
                Assert.IsNull(fallbackConsumer.Receive(TimeSpan.FromMilliseconds(1000)));

                // Close the exclusive consumer to verify the non-exclusive consumer
                // takes over
                exclusiveConsumer1.Close();

                producer.Send(msg);
                producer.Send(msg);

                Assert.IsNotNull(exclusiveConsumer2.Receive(TimeSpan.FromMilliseconds(1000)));
                Assert.IsNull(fallbackConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
            }
            finally
            {
                fallbackSession.Close();
                senderSession.Close();
                conn.Close();
            }
        }
        public void init()
        {
            IConnectionFactory fac = new ConnectionFactory("tcp://localhost:61616");
            IConnection        con = fac.CreateConnection();

            con.Start();
            ISession      session = con.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQQueue queu    = new ActiveMQQueue(QUEUE_NAME);

            producer = session.CreateProducer(queu);
        }
        public MessagePublisher(string queueName, string brokerUri)
        {
            this.queueName         = queueName;
            this.connectionFactory = new ConnectionFactory(brokerUri);
            this.connection        = this.connectionFactory.CreateConnection();
            this.connection.Start();
            this.session = connection.CreateSession();
            ActiveMQQueue queue = new ActiveMQQueue(queueName);

            this.producer = this.session.CreateProducer(queue);
        }
Esempio n. 14
0
        private void frmHome_Load(object sender, EventArgs e)
        {
            IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616");
            IConnection        con     = factory.CreateConnection("admin", "admin");

            con.Start();
            ISession         session     = con.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQQueue    destination = new ActiveMQQueue("donThuoc");
            IMessageConsumer consumer    = session.CreateConsumer(destination);

            consumer.Listener += Consumer_Listener;
        }
Esempio n. 15
0
        public void purgeQueue(IConnection conn, ActiveMQQueue queue)
        {
            ISession         session  = conn.CreateSession();
            IMessageConsumer consumer = session.CreateConsumer(queue);

            while (consumer.Receive(TimeSpan.FromMilliseconds(500)) != null)
            {
            }

            consumer.Close();
            session.Close();
        }
        private void ReceiverThongTinQueue()
        {
            IConnectionFactory factory    = new ConnectionFactory("tcp://localhost:61616");
            IConnection        connection = factory.CreateConnection("admin", "admin");

            connection.Start();
            ISession         session       = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQQueue    queue         = new ActiveMQQueue("DuongChiHieu_17044781_Queue");
            IMessageConsumer consumerqueue = session.CreateConsumer(queue);

            consumerqueue.Listener += Consumerqueue_Listener;
        }
Esempio n. 17
0
        public void init()
        {
            IConnectionFactory fac = new ConnectionFactory("tcp://localhost:61616");
            IConnection        con = fac.CreateConnection();

            con.Start();
            ISession         session  = con.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQQueue    queu     = new ActiveMQQueue("hospital");
            IMessageConsumer consumer = session.CreateConsumer(queu);

            consumer.Listener += consumer_Listener;
            Console.ReadLine();
        }
Esempio n. 18
0
        public MessageSubscriber(string queueName, string brokerUri)
        {
            this.queueName         = queueName;
            this.connectionFactory = new ConnectionFactory(brokerUri);
            this.connection        = this.connectionFactory.CreateConnection();

            this.connection.Start();
            this.session = connection.CreateSession();
            ActiveMQQueue queue = new ActiveMQQueue(queueName);

            this.consumer           = this.session.CreateConsumer(queue);
            this.consumer.Listener += new MessageListener(OnMessage);
        }
        static void Main(string[] args)
        {
            IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616");
            IConnection        con     = factory.CreateConnection("admin", "admin");

            con.Start();
            ISession         session     = con.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQQueue    destination = new ActiveMQQueue("HoangAnh");
            IMessageConsumer consumer    = session.CreateConsumer(destination);

            consumer.Listener += Consumer_Listener;
            Console.ReadLine();
        }
        public MyQueueSubscriber(string queueName, string brokerUri, string clientId)
        {
            this.topicName           = queueName;
            this.connectionFactory   = new ConnectionFactory(brokerUri);
            this.connection          = this.connectionFactory.CreateConnection();
            this.connection.ClientId = clientId;
            this.connection.Start();
            this.session = connection.CreateSession();
            ActiveMQQueue topic = new ActiveMQQueue(queueName);

            //this.consumer = this.session.CreateDurableConsumer(topic, consumerId, "2 > 1", false);
            this.consumer           = this.session.CreateConsumer(topic, "2 > 1");
            this.consumer.Listener += new MessageListener(OnMessage);
        }
        static void Main(string[] args)
        {
            IConnectionFactory factory    = new  ConnectionFactory("tcp://localhost:61616");
            IConnection        connection = factory.CreateConnection("admin", "admin");

            connection.Start();
            ISession         session  = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQQueue    queue    = new ActiveMQQueue("17044781_DuongChiHieu");
            IMessageConsumer consumer = session.CreateConsumer(queue);

            consumer.Listener += Consumer_Listener;
            while (true)
            {
            }
        }
        public static void sentString(string mess)
        {
            IConnectionFactory factory    = new ConnectionFactory("tcp://localhost:61616");
            IConnection        connection = factory.CreateConnection("admin", "admin");

            connection.Start();
            ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQQueue    destination = new ActiveMQQueue("doctor");
            IMessageProducer producer    = session.CreateProducer(destination);
            IMessage         imess       = new ActiveMQTextMessage(mess);

            producer.Send(imess);
            Console.WriteLine("Sent info: " + mess);
            session.Close();
            connection.Close();
        }
Esempio n. 23
0
        private void SendThongTinQueue(eBenhNhan bn)
        {
            IConnectionFactory factory    = new ConnectionFactory("tcp://localhost:61616");
            IConnection        connection = factory.CreateConnection("admin", "admin");

            connection.Start();
            ISession            session  = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQQueue       queue    = new ActiveMQQueue("DuongChiHieu_17044781_Queue");
            IMessageProducer    producer = session.CreateProducer(queue);
            string              x        = new ConvertXML <eBenhNhan>().O2XML(bn);
            ActiveMQTextMessage mes      = new ActiveMQTextMessage(x);

            producer.Send(mes);
            producer.Close();
            session.Close();
            connection.Close();
        }
        public static void sentXMLInfo(benhNhan bn)
        {
            IConnectionFactory factory    = new ConnectionFactory("tcp://localhost:61616");
            IConnection        connection = factory.CreateConnection("admin", "admin");

            connection.Start();
            ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQQueue    destination = new ActiveMQQueue("doctor");
            IMessageProducer producer    = session.CreateProducer(destination);
            string           xml         = new ObjectToXML <benhNhan>().ObjToXml(bn);

            Console.WriteLine("Sent XML: " + xml);
            //update database in here
            producer.Send(new ActiveMQTextMessage(xml));
            session.Close();
            connection.Close();
        }
    public void GetStats()
    {
        // Crear consumidor


        try
        {
            // Creo una cola y consumidor
            IDestination     queueReplyTo = session.CreateTemporaryQueue();
            IMessageConsumer consumer     = session.CreateConsumer(queueReplyTo);

            // Crear cola monitorizada
            string        listeningQueue = "TEST1";
            ActiveMQQueue testQueue      = session.GetQueue(listeningQueue);


            // Crear cola  y productor
            ActiveMQQueue    query    = session.GetQueue("ActiveMQ.Statistics.Destination.TEST1");
            IMessageProducer producer = session.CreateProducer(null);

            // Mandar mensaje vacío y replicar
            IMessage msg = session.CreateMessage();
            producer.Send(testQueue, msg);
            msg.NMSReplyTo = queueReplyTo;
            producer.Send(query, msg);

            // Recibir
            IMapMessage reply = (IMapMessage)consumer.Receive();


            if (reply != null)
            {
                IPrimitiveMap statsMap = reply.Body;

                foreach (string statKey in statsMap.Keys)
                {
                    Console.WriteLine("{0} = {1}", statKey, statsMap[statKey]);
                }
            }
        }
        catch (Exception e)
        {
            var t = e.Message + " " + e.StackTrace;
        }
    }
Esempio n. 26
0
        void reciver()
        {
            IConnectionFactory factory    = new NMSConnectionFactory("tcp://localhost:61616");
            IConnection        connection = factory.CreateConnection();

            connection.Start();
            ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            //IDestination destination = SessionUtil.GetDestination(session, "Example Queue");
            //IDestination destination = SessionUtil.GetDestination(session, "Ex ActiveMQQueue");
            ActiveMQQueue    destination = new ActiveMQQueue("Ex ActiveMQQueue");
            IMessageConsumer receiver    = session.CreateConsumer(destination);
            //richTextBox1.Text = receiver.ToString();
            //receiver.Listener += new MessageListener(NoiDungNhan);
            IMessage            mes = receiver.Receive();
            ActiveMQTextMessage x   = mes as ActiveMQTextMessage;

            richTextBox1.Text = x.Text;
        }
        static void Main(string[] args)
        {
            IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616");
            IConnection        con     = factory.CreateConnection("admin", "admin");

            con.Start();
            ISession         session     = con.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQQueue    destination = new ActiveMQQueue("HoangAnh");
            IMessageProducer producer    = session.CreateProducer(destination);

            for (int i = 0; i < 1000; i++)
            {
                IMessage msg = new ActiveMQTextMessage("Hello " + i);
                producer.Send(msg);
            }

            session.Close();
            con.Close();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Receiving message. Enter to exit.");
            //tạo connection factory
            IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616");
            //tạo connection
            IConnection con = factory.CreateConnection("admin", "admin");

            con.Start(); //nối tới MOM
                         //tạo session
            ISession session = con.CreateSession(AcknowledgementMode.AutoAcknowledge);
            //tạo consumer
            ActiveMQQueue    destination = new ActiveMQQueue("Võ Tuấn Phương");
            IMessageConsumer consumer    = session.CreateConsumer(destination);

            //nhận mesage - lắng nghe
            consumer.Listener += Consumer_Listener;
            Console.ReadKey();
        }
        public void Send(string message)
        {
            ITextMessage       objectMessage;
            IConnectionFactory connectionFactory = new NMSConnectionFactory(Urls.ActiveMQ);
            //IConnectionFactory connectionFactory = new NMSConnectionFactory("tcp://localhost:8888");

            IConnection connection = connectionFactory.CreateConnection();

            connection.Start();
            ISession         session         = connection.CreateSession();
            ActiveMQQueue    queue           = new ActiveMQQueue("porukeQueue, porukeQueueTestni");
            IMessageProducer messageProducer = session.CreateProducer();

            objectMessage = session.CreateTextMessage(message);

            messageProducer.Send(queue, objectMessage);
            session.Close();
            connection.Stop();
        }
Esempio n. 30
0
        public void TestExclusiveConsumerSelectedCreatedFirst()
        {
            IConnection conn = createConnection(true);

            ISession exclusiveSession = null;
            ISession fallbackSession  = null;
            ISession senderSession    = null;

            purgeQueue(conn, new ActiveMQQueue("TEST.QUEUE1"));

            try
            {
                exclusiveSession = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
                fallbackSession  = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
                senderSession    = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);

                ActiveMQQueue    exclusiveQueue    = new ActiveMQQueue("TEST.QUEUE1?consumer.exclusive=true");
                IMessageConsumer exclusiveConsumer = exclusiveSession.CreateConsumer(exclusiveQueue);

                ActiveMQQueue    fallbackQueue    = new ActiveMQQueue("TEST.QUEUE1");
                IMessageConsumer fallbackConsumer = fallbackSession.CreateConsumer(fallbackQueue);

                ActiveMQQueue senderQueue = new ActiveMQQueue("TEST.QUEUE1");

                IMessageProducer producer = senderSession.CreateProducer(senderQueue);

                IMessage msg = senderSession.CreateTextMessage("test");
                producer.DeliveryMode = MsgDeliveryMode.NonPersistent;
                producer.Send(msg);
                Thread.Sleep(500);

                // Verify exclusive consumer receives the message.
                Assert.IsNotNull(exclusiveConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
                Assert.IsNull(fallbackConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
            }
            finally
            {
                fallbackSession.Close();
                senderSession.Close();
                conn.Close();
            }
        }