public Request Pop() { try { var message = _messageConsumer.Receive(TimeSpan.FromMilliseconds(TimeOut)) as ActiveMQTextMessage; if (message == null) { return(null); } return(JsonConvert.DeserializeObject <Request>(message.Text)); } catch (NMSException nmsException) { _messageConsumer.Close(); _messageConsumer.Dispose(); _messageConsumer = null; Thread.Sleep(5000); _messageConsumer = _session.CreateConsumer(_destination); _logger.Error(nmsException); } catch (Exception exception) { _logger.Error(exception); } return(null); }
public override void Dispose() { _messageConsumer.Close(); _messageConsumer.Dispose(); base.Dispose(); GC.SuppressFinalize(this); }
/// <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(); } }
public void Dispose() { if (disposed) { return; } if (consumer != null) { consumer.Close(); consumer.Dispose(); } if (session != null) { session.Close(); session.Dispose(); } if (connection != null) { connection.Close(); connection.Dispose(); } disposed = true; }
public void Dispose() { consument.Dispose(); producer.Dispose(); session.Dispose(); connection.Dispose(); }
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; }
async Task ActiveAndActualAgentsCompleted(StopSupervisorContext context) { await Task.WhenAll(context.Agents.Select(x => Completed)).OrCanceled(context.CancellationToken).ConfigureAwait(false); if (_dispatcher.ActiveDispatchCount > 0) { try { await _deliveryComplete.Task.OrCanceled(context.CancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { LogContext.Warning?.Log("Stop canceled waiting for message consumers to complete: {InputAddress}", _context.InputAddress); } } try { _messageConsumer.Close(); _messageConsumer.Dispose(); } catch (OperationCanceledException) { LogContext.Warning?.Log("Stop canceled waiting for consumer shutdown: {InputAddress}", _context.InputAddress); } }
public void TerminateConnections() { if (_mqMessageConsumer != null) { try { _mqMessageConsumer.Close(); _mqMessageConsumer.Dispose(); } catch (Exception exception) { FdrCommon.LogEvent(exception, EventLogEntryType.Error); } } if (_mqDestination != null) { _mqDestination.Dispose(); _mqDestination = null; } if (_mqConnection != null) { _mqConnection.Close(); _mqConnection.Dispose(); } if (_newSesstion != null) { _newSesstion.Close(); _newSesstion.Dispose(); } }
public void Dispose() { connection?.Dispose(); session?.Dispose(); messageConsumer?.Dispose(); messageProducer?.Dispose(); }
async Task ActiveAndActualAgentsCompleted(StopSupervisorContext context) { await Task.WhenAll(context.Agents.Select(x => Completed)).UntilCompletedOrCanceled(context.CancellationToken).ConfigureAwait(false); if (_tracker.ActiveDeliveryCount > 0) { try { await _deliveryComplete.Task.UntilCompletedOrCanceled(context.CancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { if (_log.IsWarnEnabled) { _log.WarnFormat("Stop canceled waiting for message consumers to complete: {0}", _context.InputAddress); } } } try { _messageConsumer.Close(); _messageConsumer.Dispose(); } catch (OperationCanceledException) { if (_log.IsWarnEnabled) { _log.WarnFormat("Exception canceling the consumer: {0}", _context.InputAddress); } } }
public void Dispose() { _connection?.Close(); _session?.Dispose(); _connection?.Dispose(); _messageConsumer1?.Dispose(); _messageConsumer2?.Dispose(); }
public void DestroyMQConsumer(IMessageConsumer consumer) { if (consumer != null) { consumer.Close(); consumer.Dispose(); } }
protected override void PostStop() { _consumer.MessageReceived -= ConsumerOnMessageReceived; _consumer.Dispose(); _isStarted = false; base.PostStop(); }
public void doTestDurableConsumerSelectorChange(bool persistent) { try { using (IConnection connection = CreateConnection(TEST_CLIENT_ID)) { connection.Start(); using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) { ITopic topic = SessionUtil.GetTopic(session, TOPIC); IMessageProducer producer = session.CreateProducer(topic); IMessageConsumer consumer = session.CreateDurableConsumer(topic, CONSUMER_ID, "color='red'", false); producer.Persistent = persistent; // Send the messages ITextMessage sendMessage = session.CreateTextMessage("1st"); sendMessage.Properties["color"] = "red"; producer.Send(sendMessage); ITextMessage receiveMsg = consumer.Receive(receiveTimeout) as ITextMessage; Assert.IsNotNull(receiveMsg, "Failed to retrieve 1st durable message."); Assert.AreEqual("1st", receiveMsg.Text); Assert.AreEqual(persistent, receiveMsg.NMSPersistent, "NMSPersistent does not match"); // Change the subscription. consumer.Dispose(); consumer = session.CreateDurableConsumer(topic, CONSUMER_ID, "color='blue'", false); sendMessage = session.CreateTextMessage("2nd"); sendMessage.Properties["color"] = "red"; producer.Send(sendMessage); sendMessage = session.CreateTextMessage("3rd"); sendMessage.Properties["color"] = "blue"; producer.Send(sendMessage); // Selector should skip the 2nd message. receiveMsg = consumer.Receive(receiveTimeout) as ITextMessage; Assert.IsNotNull(receiveMsg, "Failed to retrieve durable message."); Assert.AreEqual("3rd", receiveMsg.Text, "Retrieved the wrong durable message."); Assert.AreEqual(persistent, receiveMsg.NMSPersistent, "NMSPersistent does not match"); // Make sure there are no pending messages. Assert.IsNull(consumer.ReceiveNoWait(), "Wrong number of messages in durable subscription."); } } } catch (Exception ex) { Assert.Fail(ex.Message); } finally { UnregisterDurableConsumer(TEST_CLIENT_ID, CONSUMER_ID); } }
/// <summary> /// </summary> /// <returns></returns> public override void Close() { if (_consumer != null) { _consumer.Close(); _consumer.Dispose(); _consumer = null; } base.Close(); }
public void TestSendWhileClosed(AcknowledgementMode ackMode) { try { using (IConnection connection = CreateConnection(TEST_CLIENT_ID)) { connection.Start(); using (ISession session = connection.CreateSession(ackMode)) { ITopic topic = session.GetTopic(DURABLE_TOPIC); IMessageProducer producer = session.CreateProducer(topic); producer.DeliveryMode = MsgDeliveryMode.Persistent; ISession consumeSession = connection.CreateSession(ackMode); IMessageConsumer consumer = consumeSession.CreateDurableConsumer(topic, CONSUMER_ID, null, false); Thread.Sleep(1000); consumer.Dispose(); consumer = null; ITextMessage message = session.CreateTextMessage("DurableTest-TestSendWhileClosed"); message.Properties.SetString("test", "test"); message.NMSType = "test"; producer.Send(message); if (AcknowledgementMode.Transactional == ackMode) { session.Commit(); } consumer = consumeSession.CreateDurableConsumer(topic, CONSUMER_ID, null, false); ITextMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000)) as ITextMessage; msg.Acknowledge(); if (AcknowledgementMode.Transactional == ackMode) { consumeSession.Commit(); } Assert.IsNotNull(msg); Assert.AreEqual(msg.Text, "DurableTest-TestSendWhileClosed"); Assert.AreEqual(msg.NMSType, "test"); Assert.AreEqual(msg.Properties.GetString("test"), "test"); } } } catch (Exception ex) { Assert.Fail(ex.Message); } finally { UnregisterDurableConsumer(TEST_CLIENT_ID, CONSUMER_ID); } }
/// <summary> /// 释放 /// </summary> /// <param name="disposeConnection">是否释放连接(考虑多消费者共用同一个连接的情况)</param> public void Dispose(bool disposeConnection) { _consumer?.Dispose(); _session?.Dispose(); if (disposeConnection) { ConnectionPool.Instance.DisposeConnection(_options); _connection = null; } }
/// <summary> /// 停止 /// </summary> public virtual void Stop() { if (_msgconsumer != null) { _msgconsumer.Listener -= Consumer_Listener; _msgconsumer.Dispose(); } _session?.Dispose(); _connection?.Dispose(); _connection = null; }
/// <summary> /// Dispose given IServerSession /// </summary> /// <param name="_session"></param> public void DisposeSession(IMessageConsumer _session) { if (_session != null) { if (activeSessions.TryRemove(_session, out _)) { _session.Dispose(); Interlocked.Decrement(ref activeSessionCount); } } }
public void ShouldCloseSessionWhenSubscriptionDisposed() { IDisposable subscription = _source.Messages.Subscribe(_observer); subscription.Dispose(); A.CallTo(() => _consumer.Close()).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _consumer.Dispose()).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _session.Close()).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _session.Dispose()).MustHaveHappened(Repeated.Exactly.Once); }
public override Content GetContent(string uri) { var content = new Content(); try { while (true) { var message = _messageConsumer.Receive(TimeSpan.FromMilliseconds(TimeOut)) as ActiveMQTextMessage; if (message == null) { continue; } //发送到备份队列 _messageProducer.Send(message); var htmlMessageContext = JsonConvert.DeserializeObject <HtmlMessageContext>(message.Text); if (Regex.Match(htmlMessageContext.Response.Request.Url, Filter).Success) { content.Session.Add(new NameValue("Request.Url", htmlMessageContext.Response.Request.Url)); content.ContentText = htmlMessageContext.Text; break; } } } catch (NMSException nmsException) { _messageConsumer.Close(); _messageConsumer.Dispose(); _messageConsumer = null; Thread.Sleep(2000); _messageConsumer = _session.CreateConsumer(_destinationConsumer); Console.WriteLine(nmsException); } catch (Exception exception) { Console.WriteLine(exception); } return(content); }
public void Dispose() { EventsEnabled = false; if (RK_listener != null) { RK_listener.Close(); RK_listener.OnMessage -= AvroReceived; RK_listener.Dispose(); } if (RK_publisher != null) { RK_publisher.Shutdown(); } RK_publisher = null; }
private void lv_pathList_ButtonClickEvent(object sender, EventArgs e) { if (sender is ListViewItem) { IMessageConsumer tempConsumer = (IMessageConsumer)((ListViewItem)sender).SubItems[0].Tag; tempConsumer.Close(); tempConsumer.Dispose(); consumerList.Remove(tempConsumer); ((ListViewItem)sender).SubItems[0].Tag = null; lv_pathList.DelItemEx((ListViewItem)sender); } else { ShowError("delete error"); } }
public void destoryClick() { try { consumer.Close(); consumer.Dispose(); producer.Close(); producer.Dispose(); session.Close(); session.Dispose(); connection.Stop(); connection.Close(); connection.Dispose(); } catch (Exception e) { } }
public void destroyObjects() { try { _consumer.Close(); _consumer.Dispose(); _producer.Close(); _producer.Dispose(); _session.Close(); _session.Dispose(); _connection.Stop(); _connection.Close(); _connection.Dispose(); } catch (Exception e) { } }
// Methode wird als Eventhandler für Window.Closed-Event verwendet (benoetigt sender/e Argumente) // und von UpdateConnection() aus (parameterfrei). public void CleanupResources(object sender = null, EventArgs e = null) { if (messageConsumer != null) { messageConsumer.Dispose(); } if (session != null) { session.Dispose(); } if (connection != null) { connection.Dispose(); connection = null; } connectionFactory = null; }
/// <summary> /// 取消订阅 /// </summary> /// <param name="consumerNameFullName">consumerName (为形如queue://consumerName 格式的数据)</param> /// <returns>被删除的消费者的数量(可能会有重名的会被一起删除)</returns> public int UnSubscribeConsumer(string consumerNameFullName) { int unSubscribeNumber = 0; for (int i = consumerList.Count - 1; i >= 0; i--) { IMessageConsumer tempConsumer = consumerList[i]; if (((Apache.NMS.ActiveMQ.MessageConsumer)(tempConsumer)).ConsumerInfo.Destination.ToString() == consumerNameFullName) { tempConsumer.Close(); tempConsumer.Dispose(); consumerList.RemoveAt(i); unSubscribeNumber++; } } return(unSubscribeNumber); }
protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { // Managed and unmanaged resources can be disposed. session.Close(); connection.Close(); session.Dispose(); connection.Dispose(); consumer.Dispose(); _observerList.ToList().ForEach(item => item.OnCompleted()); } } disposed = true; }
public void CreateAndDisposeWithConsumer(bool disposeConsumer) { using (IConnection connection = CreateConnection("DisposalTestConnection")) { connection.Start(); using (ISession session = connection.CreateSession()) { IQueue queue = session.GetQueue("DisposalTestQueue"); IMessageConsumer consumer = session.CreateConsumer(queue); connection.Stop(); if (disposeConsumer) { consumer.Dispose(); } } } }
public void TestSendSessionClose() { IMessage[] outbound = new IMessage[] { Session.CreateTextMessage("First Message"), Session.CreateTextMessage("Second Message") }; //sends a message producer.Send(outbound[0]); Session.Commit(); //sends a message that gets rollbacked producer.Send(Session.CreateTextMessage("I'm going to get rolled back.")); consumer.Dispose(); Session.Dispose(); Reconnect(); //sends a message producer.Send(outbound[1]); Session.Commit(); //receives the first message ArrayList messages = new ArrayList(); Console.WriteLine("About to consume message 1"); IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(1000)); messages.Add(message); Console.WriteLine("Received: " + message); //receives the second message Console.WriteLine("About to consume message 2"); message = consumer.Receive(TimeSpan.FromMilliseconds(4000)); messages.Add(message); Console.WriteLine("Received: " + message); //validates that the rollbacked was not consumed Session.Commit(); IMessage[] inbound = new IMessage[messages.Count]; messages.CopyTo(inbound); AssertTextMessagesEqual("Rollback did not work.", outbound, inbound); }