protected virtual void Dispose(bool disposing) { if (this.isDisposed) { return; } if (disposing) { if (this.queueSession != null) { if (this.queueSession.AcknowledgementMode == AcknowledgementMode.Transactional) { this.queueSession.Rollback(); } // there is a difference between calling dispose and Close on AMQ.Session object this.queueSession.Close(); } if (this.queueConnection != null) { this.queueConnection.Dispose(); } } this.queueSession = null; this.queueConnection = null; this.isDisposed = true; }
public void Initialize(bool transactionMode) { Apache.NMS.IConnectionFactory connectionFactory = new Apache.NMS.ActiveMQ.ConnectionFactory(this.configurationProvider.GetConfigurationSection <QueueingConfig>().QueueServerUri); this.queueConnection = connectionFactory.CreateConnection(); this.queueConnection.ClientId = this.connectionNameProvider.GetConnectionName(); this.queueSession = this.queueConnection.CreateSession(transactionMode ? Apache.NMS.AcknowledgementMode.Transactional : Apache.NMS.AcknowledgementMode.AutoAcknowledge); }
public void Connect() { while (!ableToSendEvents) { Uri connecturi = null; //if (textBoxSIPIPAddress.Text.StartsWith("ssl://")) //{ Console.WriteLine ("Trying to connect to ActiveMQ broker "); // connecturi = new Uri("activemq:" + textBoxSIPIPAddress.Text + ":" + textBoxSIPPort.Text + "?transport.ClientCertSubject=E%[email protected], CN%3DCommunication Tool"); // Connect to the ActiveMQ broker //} //else //{ //log4.Debug(name + ": Trying to connect to ActiveMQ broker via non-secure connection"); connecturi = new Uri ("activemq:tcp://localhost:61616"); // Connect to the ActiveMQ broker //} //Console.WriteLine("activeMQ::About to connect to " + connecturi); try { // NOTE: ensure the nmsprovider-activemq.config file exists in the executable folder. IConnectionFactory factory = new ConnectionFactory (connecturi); // Create a new connection and session for publishing events activeMQConnection = factory.CreateConnection (); activeMQSession = activeMQConnection.CreateSession (); IDestination destination = SessionUtil.GetDestination (activeMQSession, "topic://SIFTEO"); //Console.WriteLine("activeMQ::Using destination: " + destination); // Create the producer activeMQProducer = activeMQSession.CreateProducer (destination); activeMQProducer.DeliveryMode = MsgDeliveryMode.Persistent; destination = SessionUtil.GetDestination (activeMQSession, "topic://XVR.CCC"); activeMQConsumer = activeMQSession.CreateConsumer (destination); //activeMQConsumer.Listener += new MessageListener(OnCCCMessage); // Start the connection so that messages will be processed activeMQConnection.Start (); //activeMQProducer.Persistent = true; // Enable the sending of events //log4.Debug(name + ": ActiveMQ connected on topics XVR.CCC and XVR.SDK"); ableToSendEvents = true; } catch (Exception exp) { // Report the problem in the output.log (Program Files (x86)\E-Semble\XVR 2012\XVR 2012\XVR_Data\output_log.txt) //Console.WriteLine("*** AN ACTIVE MQ ERROR OCCURED: " + exp.ToString() + " ***"); //log4.Error(name + ": Error connecting to ActiveMQ broker: " + exp.Message); //log4.Error((exp.InnerException != null) ? exp.InnerException.StackTrace : ""); Console.WriteLine (exp.Message); } System.Threading.Thread.Sleep (1000); } }
/// <summary> /// Determine the reply destination for the given message /// </summary> /// <remarks> /// This implementation first checks the NMS ReplyTo Destination of the supplied request message; if that is /// not null, it is returned; if it is null, then the return value of <see cref="ResolveDefaultReplyDestination"/> /// is returned; ift his too is null, then an <see cref="InvalidDestinationException"/> if thrown /// </remarks> /// <param name="request">The original incoming NMS message.</param> /// <param name="session">The NMS session to operate on.</param> /// <returns>The reply destination (never null).</returns> /// <exception cref="InvalidDestinationException">If no <see cref="IDestination"/> can be determined. /// </exception> /// <seealso cref="DefaultReplyDestination"/> private IDestination GetReplyDestination(Apache.NMS.IMessage request, Apache.NMS.ISession session) { IDestination replyTo = request.NMSReplyTo; if (replyTo == null) { replyTo = ResolveDefaultReplyDestination(session); if (replyTo == null) { throw new InvalidDestinationException("Cannot determine reply destination: " + "Request message does not contain reply-to destination, and no default reply destination set."); } } return(replyTo); }