예제 #1
0
        public void TestMultipleCloseCallsNoErrors()
        {
            IMessageProducer producer = session.CreateProducer();

            producer.Close();
            producer.Close();
        }
예제 #2
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            // close all connections
            producer.Close();
            session.Close();
            con.Close();

            Debug.Write("######### Form is closing ###########");
        }
예제 #3
0
        public void TestSendingMessageSetsNMSDestination()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.Open();
                List <Amqp.Message> receivedMessages  = new List <Amqp.Message>();
                TestLinkProcessor   testLinkProcessor = new TestLinkProcessor(receivedMessages);
                testAmqpPeer.RegisterLinkProcessor(testLinkProcessor);

                IConnection      connection  = EstablishConnection();
                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IMessageProducer producer    = session.CreateProducer(destination);

                string       text    = "myMessage";
                ITextMessage message = session.CreateTextMessage(text);

                Assert.IsNull(message.NMSDestination);

                producer.Send(message);

                Assert.AreEqual(destination, message.NMSDestination);
                Assert.IsTrue(receivedMessages.Any());
                Assert.That(receivedMessages.First().Properties.To, Is.EqualTo(destination.QueueName));

                producer.Close();
                session.Close();
                connection.Close();
            }
        }
예제 #4
0
        public void TestProducerOverridesMessageDeliveryMode()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.Open();
                TestLinkProcessor testLinkProcessor = new TestLinkProcessor();
                testAmqpPeer.RegisterLinkProcessor(testLinkProcessor);

                IConnection      connection  = EstablishConnection();
                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IMessageProducer producer    = session.CreateProducer(destination);

                string       text        = "myMessage";
                ITextMessage textMessage = session.CreateTextMessage(text);
                textMessage.NMSDeliveryMode = MsgDeliveryMode.NonPersistent;

                producer.Send(textMessage);

                Assert.AreEqual(MsgDeliveryMode.Persistent, textMessage.NMSDeliveryMode);

                producer.Close();
                session.Close();
                connection.Close();
            }
        }
예제 #5
0
        /// <summary>
        /// Envia un mensaje vacío a la cola especificada.
        /// </summary>
        /// <param name="queueName"></param>
        /// <returns></returns>
        public void CrearSessionAtomica(string queueName)
        {
            try
            {
                IConnection connection = CrearSessionAtomica(ServidorBrokerUri,
                                                             AcknowledgementMode.AutoAcknowledge,
                                                             UserName,
                                                             Password,
                                                             queueName);

                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = SessionUtil.GetDestination(session, queueName);
                    using (IMessageProducer producer = session.CreateProducer(destination))
                    {
                        ITextMessage textMessage = producer.CreateTextMessage();
                        producer.DeliveryMode            = MsgDeliveryMode.NonPersistent;
                        producer.DisableMessageID        = true;
                        producer.DisableMessageTimestamp = true;
                        producer.Send(textMessage);
                        producer.Priority   = MsgPriority.Lowest;
                        producer.TimeToLive = TimeSpan.MinValue;
                        producer.Close();
                        //connection.PurgeTempDestinations();
                    }
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                Log.Error(ex, Constantes.MsgLog.ERRORMETODO, nameof(CrearSessionAtomica));
                throw ex;
            }
        }
예제 #6
0
        public void TestSendWorksAfterConnectionStopped()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.Open();
                List <Amqp.Message> receivedMessages  = new List <Amqp.Message>();
                TestLinkProcessor   testLinkProcessor = new TestLinkProcessor(receivedMessages);
                testAmqpPeer.RegisterLinkProcessor(testLinkProcessor);

                IConnection connection = EstablishConnection();
                connection.Start();
                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IMessageProducer producer    = session.CreateProducer(destination);

                string       text    = "myMessage";
                ITextMessage message = session.CreateTextMessage(text);

                Assert.IsNull(message.NMSMessageId);

                connection.Stop();

                producer.Send(message);

                Assert.IsTrue(receivedMessages.Any());

                producer.Close();
                session.Close();
                connection.Close();
            }
        }
예제 #7
0
        public void TestSendWhenLinkCreditIsZeroAndTimeout()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.Open();
                testAmqpPeer.RegisterLinkProcessor(new MockLinkProcessor(context =>
                {
                    context.Complete(new TestLinkEndpoint(new List <Amqp.Message>()), 0);
                }));

                IConnection      connection  = EstablishConnection("nms.sendTimeout=500");
                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IMessageProducer producer    = session.CreateProducer(destination);

                string       text    = "myMessage";
                ITextMessage message = session.CreateTextMessage(text);

                Assert.Catch <Exception>(() => producer.Send(message));

                producer.Close();
                session.Close();
                connection.Close();
            }
        }
예제 #8
0
        public void TestNonDefaultPriorityProducesMessagesWithPriorityFieldAndSetsNMSPriority()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.Open();
                List <Amqp.Message> receivedMessages  = new List <Amqp.Message>();
                TestLinkProcessor   testLinkProcessor = new TestLinkProcessor(receivedMessages);
                testAmqpPeer.RegisterLinkProcessor(testLinkProcessor);

                IConnection      connection  = EstablishConnection();
                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IMessageProducer producer    = session.CreateProducer(destination);

                string       text    = "myMessage";
                ITextMessage message = session.CreateTextMessage(text);


                Assert.AreEqual(MsgPriority.BelowNormal, message.NMSPriority);
                producer.Send(message, MsgDeliveryMode.Persistent, MsgPriority.Highest, NMSConstants.defaultTimeToLive);

                Assert.AreEqual(MsgPriority.Highest, message.NMSPriority);
                Assert.IsTrue(receivedMessages.Any());
                Assert.AreEqual(9, receivedMessages.First().Header.Priority);

                producer.Close();
                session.Close();
                connection.Close();
            }
        }
        /// <summary>
        /// Instruct this <see cref="ActiveMQCache" /> to disconnect from a remote cache system if required.
        /// </summary>
        public override void Disconnect()
        {
            if (mConsumer != null)
            {
                mConsumer.Close();
                mConsumer.Dispose();
            }

            if (mProducer != null)
            {
                mProducer.Close();
                mProducer.Dispose();
            }

            if (mSession != null)
            {
                mSession.Close();
                mSession.Dispose();
            }

            if (mConnector != null)
            {
                mConnector.Stop();
                mConnector.Close();
                mConnector.Dispose();
            }
        }
예제 #10
0
        public void TestSelectorsWithJMSType()
        {
            PurgeQueue(TimeSpan.FromMilliseconds(500));

            Connection = CreateAmqpConnection();
            Connection.Start();

            ISession         session  = Connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            IQueue           queue    = session.GetQueue(TestName);
            IMessageProducer producer = session.CreateProducer(queue);

            ITextMessage message1 = session.CreateTextMessage("text");

            producer.Send(message1, MsgDeliveryMode.Persistent, MsgPriority.Normal, TimeSpan.Zero);

            string       type     = "myJMSType";
            string       text     = "text" + type;
            ITextMessage message2 = session.CreateTextMessage(text);

            message2.NMSType = type;
            producer.Send(message2, MsgDeliveryMode.Persistent, MsgPriority.Highest, TimeSpan.Zero);

            producer.Close();

            IMessageConsumer messageConsumer = session.CreateConsumer(queue, $"JMSType = '{type}'");
            IMessage         msg             = messageConsumer.Receive(TimeSpan.FromSeconds(5));

            Assert.NotNull(msg, "No message was received");
            Assert.IsInstanceOf <ITextMessage>(msg);
            Assert.AreEqual(text, ((ITextMessage)msg).Text);
            Assert.IsNull(messageConsumer.Receive(TimeSpan.FromSeconds(1)));
        }
예제 #11
0
파일: MQHelper.cs 프로젝트: cooperay/mpos
        public Boolean sendMessage(String messageText)
        {
            ISession session = null;

            try
            {
                session = conn.CreateSession();
            }catch (Exception e)
            {
                return(false);
            }
            if (session == null)
            {
                return(false);
            }
            IMessageProducer prod = session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue(queue));
            //创建一个发送的消息对象
            ITextMessage message = prod.CreateTextMessage();

            //给这个对象赋实际的消息

            message.Text = messageText;
            //设置消息对象的属性,这个很重要哦,是Queue的过滤条件,也是P2P消息的唯一指定属性
            message.Properties.SetString("filter", "demo");
            //生产者把消息发送出去,几个枚举参数MsgDeliveryMode是否长链,MsgPriority消息优先级别,发送最小单位,当然还有其他重载
            prod.Send(message, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue);
            prod.Close();
            session.Close();

            return(true);
        }
        public void Enqueue(DbConnection connection, DbTransaction transaction, string queue, string jobId)
        {
            if (!_client.IsStarted)
            {
                _client.Start();
            }

            using (ISession session = _client.CreateSession())
            {
                try
                {
                    IDestination destination = null;
                    destination = session.GetQueue(queue);

                    IMessageProducer producer = session.CreateProducer(destination);
                    producer.DeliveryMode = MsgDeliveryMode.Persistent;

                    IMessage objMessage = null;
                    objMessage = producer.CreateTextMessage(jobId);

                    producer.Send(objMessage);
                    producer.Close();
                }
                catch (Exception ex)
                {
                    //_log.Error(ex);
                }
                finally
                {
                    session.Close();
                }
            }
        }
        public void TestSendWorksAfterConnectionStopped()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                IConnection connection = EstablishConnection(testPeer);
                connection.Start();

                testPeer.ExpectBegin();
                testPeer.ExpectSenderAttach();

                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IMessageProducer producer    = session.CreateProducer(destination);

                testPeer.ExpectTransfer(Assert.IsNotNull);

                connection.Stop();

                producer.Send(session.CreateMessage());

                testPeer.ExpectDetach(expectClosed: true, sendResponse: true, replyClosed: true);
                testPeer.ExpectClose();

                producer.Close();
                connection.Close();

                testPeer.WaitForAllMatchersToComplete(1000);
            }
        }
예제 #14
0
        public void testOptimizedAckWithExpiredMsgsSync2()
        {
            ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            IDestination     destination = session.GetQueue("TestOptimizedAckWithExpiredMsgs");
            IMessageConsumer consumer    = session.CreateConsumer(destination);
            IMessageProducer producer    = session.CreateProducer(destination);

            producer.DeliveryMode = MsgDeliveryMode.NonPersistent;

            ITextMessage message;

            // Produce msgs that don't expire
            for (int i = 0; i < 56; i++)
            {
                message = session.CreateTextMessage();
                producer.Send(message,
                              MsgDeliveryMode.NonPersistent,
                              MsgPriority.Normal,
                              TimeSpan.FromMilliseconds(60000));
            }

            // Produce msgs that will expire quickly
            for (int i = 0; i < 44; i++)
            {
                message = session.CreateTextMessage();
                producer.Send(message,
                              MsgDeliveryMode.NonPersistent,
                              MsgPriority.Normal,
                              TimeSpan.FromMilliseconds(200));
            }

            // Produce some moremsgs that don't expire
            for (int i = 0; i < 4; i++)
            {
                message = session.CreateTextMessage();
                producer.Send(message,
                              MsgDeliveryMode.NonPersistent,
                              MsgPriority.Normal,
                              TimeSpan.FromMilliseconds(60000));
            }

            Thread.Sleep(1000);
            connection.Start();

            int counter = 0;

            for (; counter < 60; ++counter)
            {
                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(5000)));
            }

            Assert.AreEqual(60, counter, "Failed to receive all expected messages");
            Assert.IsNull(consumer.Receive(TimeSpan.FromMilliseconds(2000)));

            // Cleanup
            producer.Close();
            consumer.Close();
            session.Close();
            connection.Close();
        }
예제 #15
0
        public void Dispose()
        {
            if (disposed)
            {
                return;
            }

            sender.Close();
            sender.Dispose();

            if (receiver != null)
            {
                receiver.Close();
                receiver.Dispose();
            }

            session.Close();
            session.Dispose();

            connection.Stop();
            connection.Close();
            connection.Dispose();

            disposed = true;
        }
예제 #16
0
        private void Close()
        {
            if (_messageConsumer != null)
            {
                _messageConsumer.Close();
                _messageConsumer.Dispose();
                _messageConsumer = null;
            }

            if (_messageProducer != null)
            {
                _messageProducer.Close();
                _messageProducer.Dispose();
                _messageProducer = null;
            }

            if (_session != null)
            {
                _session.Close();
                _session.Dispose();
                _session = null;
            }

            if (_connection != null)
            {
                _connection.Close();
                _connection.Dispose();
                _connection = null;
            }
        }
예제 #17
0
        public void TestSendingMessageSetsNMSExpirationRelatedAbsoluteExpiryAndTtlFields()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.Open();
                List <Amqp.Message> receivedMessages  = new List <Amqp.Message>();
                TestLinkProcessor   testLinkProcessor = new TestLinkProcessor(receivedMessages);
                testAmqpPeer.RegisterLinkProcessor(testLinkProcessor);

                IConnection      connection  = EstablishConnection();
                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IMessageProducer producer    = session.CreateProducer(destination);

                TimeSpan ttl        = TimeSpan.FromMilliseconds(100_000);
                DateTime expiration = DateTime.UtcNow + ttl;

                string       text    = "myMessage";
                ITextMessage message = session.CreateTextMessage(text);

                producer.Send(message, NMSConstants.defaultDeliveryMode, NMSConstants.defaultPriority, ttl);

                Assert.IsTrue(receivedMessages.Any());
                Assert.That(receivedMessages.First().Properties.AbsoluteExpiryTime, Is.EqualTo(expiration).Within(TimeSpan.FromMilliseconds(100)));

                producer.Close();
                session.Close();
                connection.Close();
            }
        }
예제 #18
0
 private void EndSession()
 {
     consumer.Close();
     producer.Close();
     session.Close();
     connection.Close();
 }
예제 #19
0
        public void TestRemotelyCloseProducer()
        {
            ManualResetEvent producentClosed = new ManualResetEvent(false);
            Mock <INmsConnectionListener> mockConnectionListener = new Mock <INmsConnectionListener>();

            mockConnectionListener
            .Setup(listener => listener.OnProducerClosed(It.IsAny <NmsMessageProducer>(), It.IsAny <Exception>()))
            .Callback(() => { producentClosed.Set(); });

            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.Open();
                TestLinkProcessor testLinkProcessor = new TestLinkProcessor();
                testAmqpPeer.RegisterLinkProcessor(testLinkProcessor);

                NmsConnection connection = (NmsConnection)EstablishConnection();
                connection.AddConnectionListener(mockConnectionListener.Object);

                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IMessageProducer producer    = session.CreateProducer(destination);

                testLinkProcessor.Producer.Link.Close();

                Assert.True(producentClosed.WaitOne(TimeSpan.FromMilliseconds(1000)));
                Assert.That(() => producer.DisableMessageID, Throws.Exception.InstanceOf <IllegalStateException>());

                producer.Close();
                session.Close();
                connection.Close();
            }
        }
예제 #20
0
        public void TestCreateProducerInOnMessage()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.RegisterLinkProcessor(new TestLinkProcessor());
                testAmqpPeer.Open();

                NmsConnection connection = (NmsConnection)EstablishConnection();
                connection.Start();
                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IQueue           outbound    = session.GetQueue("ForwardDest");
                IMessageConsumer consumer    = session.CreateConsumer(destination);

                consumer.Listener += message =>
                {
                    IMessageProducer producer = session.CreateProducer(outbound);
                    producer.Send(message);
                    producer.Close();
                };

                consumer.Close();
                session.Close();
                connection.Close();
            }
        }
예제 #21
0
        public void TestSendTimesOutWhenNoDispositionArrives()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.Open();
                testAmqpPeer.RegisterLinkProcessor(new MockLinkProcessor(context =>
                {
                    context.Complete(new MockLinkEndpoint(onDispositionHandler: dispositionContext =>
                    {
                        dispositionContext.Complete();
                    }, onMessageHandler: messageContext =>
                    {
                        // do nothing
                    }), 1);
                }));

                IConnection      connection  = EstablishConnection("nms.sendTimeout=500");
                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IMessageProducer producer    = session.CreateProducer(destination);

                string       text    = "myMessage";
                ITextMessage message = session.CreateTextMessage(text);

                Assert.Catch <Exception>(() => producer.Send(message));

                producer.Close();
                session.Close();
                connection.Close();
            }
        }
예제 #22
0
        public void Stop()
        {
            if (session != null)
            {
                if (producer != null)
                {
                    producer.Close();
                }
                producer = null;
                if (consumer != null)
                {
                    consumer.Close();
                }
                consumer = null;
                session.Close();
                session = null;
                if (messageBuffer != null)
                {
                    lock (messageBuffer)
                    {
                        messageBuffer.Clear();
                        messageBuffer = null;
                    }
                }
                connection.Stop();
                connection.Close();
                connection = null;

                useZipFlag = false;
            }
        }
예제 #23
0
        public void TestSentTextMessageCanBeModified()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.Open();
                TestLinkProcessor testLinkProcessor = new TestLinkProcessor();
                testAmqpPeer.RegisterLinkProcessor(testLinkProcessor);

                IConnection      connection  = EstablishConnection();
                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IMessageProducer producer    = session.CreateProducer(destination);

                string       text        = "myMessage";
                ITextMessage textMessage = session.CreateTextMessage(text);
                producer.Send(textMessage);

                Assert.AreEqual(text, textMessage.Text);
                textMessage.Text = text + text;
                Assert.AreEqual(text + text, textMessage.Text);

                producer.Close();
                session.Close();
                connection.Close();
            }
        }
예제 #24
0
        public void TestSendingMessageSetsNMSTimestamp()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                testAmqpPeer.Open();
                List <Amqp.Message> receivedMessages  = new List <Amqp.Message>();
                TestLinkProcessor   testLinkProcessor = new TestLinkProcessor(receivedMessages);
                testAmqpPeer.RegisterLinkProcessor(testLinkProcessor);

                IConnection      connection  = EstablishConnection();
                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IMessageProducer producer    = session.CreateProducer(destination);

                DateTime timeStamp = DateTime.UtcNow;

                string       text    = "myMessage";
                ITextMessage message = session.CreateTextMessage(text);

                producer.Send(message);

                Assert.IsTrue(receivedMessages.Any());
                Assert.That(receivedMessages.First().Properties.CreationTime, Is.EqualTo(timeStamp).Within(TimeSpan.FromMilliseconds(100)));

                producer.Close();
                session.Close();
                connection.Close();
            }
        }
예제 #25
0
 static void Main(string[] args)
 {
     try
     {
         IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616/");
         using (IConnection connection = factory.CreateConnection())
         {
             using (ISession session = connection.CreateSession())
             {
                 IMessageProducer prod = session.CreateProducer(
                     new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("testing"));
                 int i = 0;
                 for (int j = 0; j < 2; j++)
                 {
                     ITextMessage msg = prod.CreateTextMessage();
                     msg.Text = i.ToString();
                     msg.Properties.SetString("filter", "zch");
                     Console.WriteLine("Sending: " + i.ToString());
                     prod.Send(msg, Apache.NMS.MsgDeliveryMode.NonPersistent, Apache.NMS.MsgPriority.Normal, TimeSpan.MinValue);
                     System.Threading.Thread.Sleep(100);
                     i++;
                 }
                 prod.Close();
                 session.Close();
             }
             connection.Stop();
             connection.Close();
         }
     }
     catch (System.Exception e)
     {
         Console.WriteLine("{0}", e.Message);
         Console.ReadLine();
     }
 }
        public void Requeue()
        {
            if (!_client.IsStarted)
            {
                _client.Start();
            }

            using (ISession session = _client.CreateSession())
            {
                try
                {
                    IDestination destination = null;
                    destination = session.GetQueue(_queueName);

                    IMessageProducer producer = session.CreateProducer(destination);
                    producer.DeliveryMode = MsgDeliveryMode.Persistent;

                    IMessage objMessage = null;
                    objMessage = producer.CreateTextMessage(_message.Text);

                    producer.Send(objMessage);
                    producer.Close();
                }
                catch (Exception ex)
                {
                    //_log.Error(ex);
                }
                finally
                {
                    session.Close();
                }
            }
        }
예제 #27
0
        private void Connect()
        {
            if (_disposable == null)
            {
                lock (_gate)
                {
                    if (_disposable == null)
                    {
                        _session  = _connection.Value.CreateSession(Apache.NMS.AcknowledgementMode.AutoAcknowledge);
                        _producer = _session.CreateProducer(_destination);

                        _disposable = Disposable.Create(() =>
                        {
                            _disposed = true;

                            DrainScheduler();

                            _producer.Close();
                            _producer.Dispose();
                            _session.Close();
                            _session.Dispose();
                        });
                    }
                }
            }
        }
        private void closeConnection()
        {
            try
            {
                producer.Close();
            }
            catch { }

            try
            {
                session.Close();
            }
            catch { }

            try
            {
                connection.Stop();
            }
            catch { }

            try
            {
                connection.Close();
            }
            catch { }

            producer   = null;
            session    = null;
            connection = null;
        }
예제 #29
0
        private void CloseProducer()
        {
            string strProcedureName =
                string.Format(
                    "{0}.{1}",
                    className,
                    MethodBase.GetCurrentMethod().Name);

            if (producer != null)
            {
                producer.Close();
                producer = null;
            }
            if (session != null)
            {
                session.Close();
                session = null;
            }
            if (connection != null)
            {
                connection.Close();
                connection = null;
            }

            factory = null;

            esbConnectStatus   = 0;
            lastESBConnectTime = DateTime.Now;

            OutputLog("停止服务,关闭 ESB 连接。", strProcedureName, ToolTipIcon.Info);
        }
        private void PopulateDestinationWithInterleavedProducer(int nbMessages, string destinationName)
        {
            ISession         session1     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            IDestination     destination1 = session1.GetQueue(destinationName);
            IMessageProducer producer1    = session1.CreateProducer(destination1);

            producer1.DeliveryMode = MsgDeliveryMode.NonPersistent;

            ISession         session2     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            IDestination     destination2 = session2.GetQueue(destinationName);
            IMessageProducer producer2    = session2.CreateProducer(destination2);

            producer2.DeliveryMode = MsgDeliveryMode.NonPersistent;

            for (int i = 1; i <= nbMessages; i++)
            {
                if (i % 2 == 0)
                {
                    producer1.Send(session1.CreateTextMessage("<hello id='" + i + "'/>"));
                }
                else
                {
                    producer2.Send(session2.CreateTextMessage("<hello id='" + i + "'/>"));
                }
            }

            producer1.Close();
            session1.Close();
            producer2.Close();
            session2.Close();
        }
예제 #31
0
        /// <summary> Close the given NMS MessageProducer and ignore any thrown exception.
		/// This is useful for typical <code>finally</code> blocks in manual NMS code.
		/// </summary>
		/// <param name="producer">the NMS MessageProducer to close (may be <code>null</code>)
		/// </param>
        public static void CloseMessageProducer(IMessageProducer producer)
        {
            if (producer != null)
            {
                try
                {
                    producer.Close();
                }
                catch (NMSException ex)
                {
                    logger.Debug("Could not close NMS MessageProducer", ex);
                }
                catch (Exception ex)
                {
                    // We don't trust the NMS provider: It might throw RuntimeException or Error.
                    logger.Debug("Unexpected exception on closing NMS MessageProducer", ex);
                }
            }
        }
예제 #32
0
 private void CloseProducerSessionConnection(IMessageProducer mockProducer)
 {
     mockProducer.Close();
     LastCall.On(mockProducer).Repeat.Once();
     mockSession.Close();
     LastCall.On(mockSession).Repeat.Once();
     mockConnection.Close();
     LastCall.On(mockConnection).Repeat.Once();
 }