public EmsWorkItem ( decimal id, int externalEntityId, WorkItemState workItemState, SubmissionPriority submissionPriority, byte[] messageBody, bool assigned, bool isRetry, string ownerName, ContextIdentifier contextIdentifier, EmsReaderQueue queue, Message message ) : base ( id, externalEntityId, workItemState, submissionPriority, messageBody, assigned, isRetry, ownerName, contextIdentifier ) { this.queue = queue; this.message = message; }
/// <summary> /// Convert from a EMS Message to a .NET object. /// </summary> /// <param name="messageToConvert">the message to convert</param> /// <returns>the converted .NET object</returns> /// <throws>MessageConversionException in case of conversion failure </throws> public object FromMessage(Message messageToConvert) { if (messageToConvert == null) { throw new MessageConversionException("Can't convert null message"); } try { string converterId = messageToConvert.GetStringProperty(typeMapper.TypeIdFieldName); if (converterId == null) { return defaultMessageConverter.FromMessage(messageToConvert); } TextMessage textMessage = messageToConvert as TextMessage; if (textMessage == null) { throw new MessageConversionException("Can't convert message of type " + messageToConvert.GetType()); } using (MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(textMessage.Text))) { XmlSerializer xs = new XmlSerializer(GetTargetType(textMessage)); XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); return xs.Deserialize(memoryStream); } } catch (Exception e) { throw new MessageConversionException("Can't convert message of type " + messageToConvert.GetType(), e); } }
public TibcoMessageSelector(TibcoEndpoint endpoint, Session session, Message transportMessage, IMessageSerializer serializer) { _endpoint = endpoint; _session = session; _transportMessage = transportMessage; _serializer = serializer; }
public static void SendReplyMessage(TIBCO.EMS.Message ReplyMessage, TIBCO.EMS.Queue ReplyQueue) { try { Session session = Messaging.EMS.Connection.EMSQueueConnection.connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); Messaging.EMS.Producers.Messageproducer.SendReplyMessage(ReplyMessage, ReplyQueue, ref session); } catch (EMSException e) { throw e; } }
public static void SendReplyMessage(TIBCO.EMS.Message msg, TIBCO.EMS.Queue ReplyQueue, ref Session session) { try { TIBCO.EMS.MessageProducer producer = session.CreateProducer(ReplyQueue); producer.Send(msg); } catch (EMSException e) { throw e; } }
public void Commit(Message msg) { if (session.IsTransacted) { Commit(); } else { msg.Acknowledge(); } }
public static Message SendRequestAndReceiveReply(TIBCO.EMS.Message msg, TIBCO.EMS.Queue queue) { try { QueueSession session = Messaging.EMS.Connection.EMSQueueConnection.connection.CreateQueueSession(false, Session.AUTO_ACKNOWLEDGE); TIBCO.EMS.QueueRequestor qr = new TIBCO.EMS.QueueRequestor(session, queue); Message ReplyMessage = qr.Request(msg); qr.Close(); return(ReplyMessage); } catch (EMSException e) { throw e; } }
public void OnMessage(Message message) { messageCount++; LOG.Debug("Message listener count = " + messageCount); TextMessage textMessage = message as TextMessage; if (textMessage != null) { LOG.Info("Message Text = " + textMessage.Text); } else { LOG.Warn("Can not process message of type " + message.GetType()); } }
public static void SendMessage(TIBCO.EMS.Message msg, TIBCO.EMS.Queue queue) { try { Session session = Messaging.EMS.Connection.EMSQueueConnection.connection.CreateSession(false, Session.CLIENT_ACKNOWLEDGE); TIBCO.EMS.MessageProducer producer = session.CreateProducer(queue); producer.Send(msg); } catch (EMSException e) { throw e; } }
public void OnException(Message msg, Exception ex) { try { Utilities.WriteLog(String.Format(@"Error sending message {0}.", ((TextMessage)msg).Text)); } catch (EMSException e) { Utilities.WriteLog(String.Format(@"Error retrieving message text.")); Utilities.WriteLog(String.Format(@"Message: " + e.Message)); Utilities.WriteLog(String.Format(e.StackTrace)); } Utilities.WriteLog(String.Format(@"Message: " + ex.Message)); Utilities.WriteLog(String.Format(ex.StackTrace)); }
public void OnCompletion(Message msg) { string msgText = ((TextMessage)msg).Text; BaseRequest baseRequest = xmlHelper.OutputXMLParse2BaseResponse(msgText); try { Utilities.WriteLog(String.Format(@"Successfully sent message {0} {1}.", msg.MessageID, msgText.Substring(0,100))); _model.fsp_MessageLog_OutputEMSUpdate(baseRequest.MessageLogId, msg.MessageID, 0,"OK", Utilities.ConvertFromUnixToDateTime(msg.DeliveryTime), 0); } catch (EMSException e) { Utilities.WriteLog(String.Format(@"Error retrieving message text.")); Utilities.WriteLog(String.Format(@"Message: " + e.Message)); Utilities.WriteLog(String.Format(e.StackTrace)); _model.fsp_MessageLog_OutputEMSUpdate(baseRequest.MessageLogId, msg.MessageID, -1, e.Message, Utilities.ConvertFromUnixToDateTime(msg.DeliveryTime), 0); } }
public void OnCompletion(TIBCO.EMS.Message msg) { try { rtb.Invoke((MethodInvoker) delegate() { rtb.Text = rtb.Text + "\nSuccessfully sent message " + ((TextMessage)msg).Text; }); log.Info("nSuccessfully sent message " + ((TextMessage)msg).Text); } catch (EMSException e) { rtb.Invoke((MethodInvoker) delegate() { rtb.Text = rtb.Text + "\nError retrieving message text."; rtb.Text = rtb.Text + "\nMessage: " + e.Message; rtb.Text = rtb.Text + "\n" + e.StackTrace; log.Error(e, "Error retrieving message text."); }); } }
/// <summary> Convert from a EMS Message to a .NET object.</summary> /// <param name="messageToConvert">the message to convert /// </param> /// <returns> the converted .NET object /// </returns> /// <throws>MessageConversionException in case of conversion failure </throws> public object FromMessage(Message messageToConvert) { if (messageToConvert is TextMessage) { return ExtractStringFromMessage((TextMessage) messageToConvert); } if (messageToConvert is BytesMessage) { return ExtractByteArrayFromMessage((BytesMessage) messageToConvert); } if (messageToConvert is MapMessage) { return ExtractMapFromMessage((MapMessage) messageToConvert); } if (messageToConvert is ObjectMessage) { return ExtractSerializableFromMessage((ObjectMessage) messageToConvert); } return messageToConvert; }
public override void OnMessage(TIBCO.EMS.Message msg) { /* * Herein will lie the call to AMT report , to pass on the msg consumed from EMS Queue . * Also, any response returned from AMT report call can be sent back to requestor * as the reply-queue and correlation-id are avaible as part of JMS Header of msg . * Not to be confused with void return .Also bear in mind , as many max. concurrent * invocations of Onmessage will be allowed ,as specfied in NoOfSessions parameter passed to * constructor as shown above.In other words ,If NoOfSessions=5 , 5 threads will be * created to excute as many instances of OnMessage, at a time. */ try { Messaging.EMS.CommonUtils.ProcessEMSMessage(msg); } catch (EMSException e) { Console.Write("\n\n(******** Exception :\n" + e.StackTrace); msg.Acknowledge(); } }
public void OnException(TIBCO.EMS.Message msg, Exception ex) { try { rtb.Invoke((MethodInvoker) delegate() { rtb.Text = rtb.Text + "\nError sending message " + ((TextMessage)msg).Text; }); log.Error("Error sending message " + ((TextMessage)msg).Text); } catch (EMSException e) { rtb.Invoke((MethodInvoker) delegate() { rtb.Text = rtb.Text + "\nError retrieving message text."; rtb.Text = rtb.Text + "\nMessage: " + e.Message; rtb.Text = rtb.Text + "\n" + e.StackTrace; log.Error(e, "Error retrieving message text."); }); } rtb.Invoke((MethodInvoker) delegate() { rtb.Text = rtb.Text + "\nMessage: " + ex.Message; rtb.Text = rtb.Text + "\n" + ex.StackTrace; }); }
/// <summary> /// Sends a message to the specified destination. /// </summary> /// <param name="destination">The destination.</param> /// <param name="message">The message.</param> public void Send(Destination destination, Message message) { target.Send(destination, message, this.deliveryMode, this.priority, this.timeToLive); }
public void Send(Message message, MessageDeliveryMode deliveryMode, int priority, long timeToLive) { target.Send(message, deliveryMode, priority, timeToLive); }
public void Send(Destination dest, Message message, MessageDeliveryMode deliveryMode, int priority, long timeToLive) { target.Send(dest, message, deliveryMode, priority, timeToLive); }
/// <summary> /// Executes the specified listener, /// committing or rolling back the transaction afterwards (if necessary). /// </summary> /// <param name="session">The session to operate on.</param> /// <param name="message">The received message.</param> /// <see cref="InvokeListener"/> /// <see cref="CommitIfNecessary"/> /// <see cref="RollbackOnExceptionIfNecessary"/> /// <see cref="HandleListenerException"/> public virtual void ExecuteListener(ISession session, Message message) { try { DoExecuteListener(session, message); } catch (Exception ex) { HandleListenerException(ex); } }
public void SendMessage(Message message) { messageListener.OnMessage(message); }
public void OnMessage(Message message) { lastReceivedMessage = message; messageCount++; LOG.Debug("Message listener count = " + messageCount); }
/* /// <summary> /// Gets or sets a value indicating whether the EmsTemplate should itself /// be responsible for caching EMS Connection/Session/MessageProducer as compared to /// creating new instances per operation (unless such resources are already /// present in Thread-Local storage either due to the use of EmsTransactionMananger or /// SimpleMessageListenerContainer at an outer calling layer. /// </summary> /// <remarks>Connection/Session/MessageProducer are thread-safe classes in TIBCO EMS.</remarks> /// <value><c>true</c> to locally cache ems resources; otherwise, <c>false</c>.</value> virtual public bool CacheEmsResources { get { return cacheEmsResources; } set { cacheEmsResources = value; } }*/ #endregion /// <summary> /// Extract the content from the given JMS message. /// </summary> /// <param name="message">The Message to convert (can be <code>null</code>).</param> /// <returns>The content of the message, or <code>null</code> if none</returns> protected virtual object DoConvertFromMessage(Message message) { if (message != null) { return MessageConverter.FromMessage(message); } return null; }
public void Send(Message message) { throw new NotImplementedException(); }
public void Consumer() { int ackMode = Session.AUTO_ACKNOWLEDGE; TIBCO.EMS.Message msg = null; while (true) { try { // receive the message msg = msgConsumer.Receive(); } catch (EMSException EMSex) { LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + EMSex.Message; }); logger.Error(EMSex.Message); } if (msg == null) { break; } if (ackMode == Session.CLIENT_ACKNOWLEDGE || ackMode == Session.EXPLICIT_CLIENT_ACKNOWLEDGE || ackMode == Session.EXPLICIT_CLIENT_DUPS_OK_ACKNOWLEDGE) { msg.Acknowledge(); } LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\nReceived message: " + msg; }); logger.Info("Received message: " + msg); if (msg is TextMessage) { TextMessage tm = (TextMessage)msg; //ReceveMsgTextBox.Text = tm.Text; ReceveMsgTextBox.Invoke((MethodInvoker) delegate() { ReceveMsgTextBox.Text = tm.Text; }); logger.Info(tm.Text); } if (msg is BytesMessage) { BytesMessage bm = (BytesMessage)msg; LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadBoolean(); }); LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadChar(); }); LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadShort(); }); LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadInt(); }); LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadLong(); }); LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadFloat(); }); LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadDouble(); }); } if (msg is MapMessage) { MapMessage mm = (MapMessage)msg; var mapNames = mm.GetMapNames(); LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.ToString(); }); /* foreach (String name in mapNames) * { * LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetBoolean(name); }); * LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetByte(name); }); * LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetBytes(name); }); * LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetChar(name); }); * LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetShort(name); }); * LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetInt(name); }); * LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetLong(name); }); * LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetFloat(name); }); * LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetDouble(name); }); * LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetString(name); }); * LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetObject(name); }); * }*/ } } }
/// <summary> /// Perform a commit or message acknowledgement, as appropriate /// </summary> /// <param name="session">The session to commit.</param> /// <param name="message">The message to acknowledge.</param> /// <exception cref="EMSException">In case of commit failure</exception> protected virtual void CommitIfNecessary(ISession session, Message message) { // Commit session or acknowledge message if (session.Transacted) { // Commit necessary - but avoid commit call is Session transaction is externally coordinated. if (IsSessionLocallyTransacted(session)) { EmsUtils.CommitIfNecessary(session); } } else if (IsClientAcknowledge(session)) { message.Acknowledge(); } }
/// <summary> /// Invoke the specified listener as Spring ISessionAwareMessageListener, /// exposing a new EMS Session (potentially with its own transaction) /// to the listener if demanded. /// </summary> /// <param name="listener">The Spring ISessionAwareMessageListener to invoke.</param> /// <param name="session">The session to operate on.</param> /// <param name="message">The received message.</param> /// <exception cref="EMSException">If thrown by EMS API methods.</exception> /// <see cref="ISessionAwareMessageListener"/> /// <see cref="ExposeListenerSession"/> protected virtual void DoInvokeListener(ISessionAwareMessageListener listener, ISession session, Message message) { IConnection conToClose = null; ISession sessionToClose = null; try { ISession sessionToUse = session; if (!ExposeListenerSession) { //We need to expose a separate Session. conToClose = CreateConnection(); sessionToClose = CreateSession(conToClose); sessionToUse = sessionToClose; } // Actually invoke the message listener if (logger.IsDebugEnabled) { logger.Debug("Invoking listener with message of type [" + message.GetType() + "] and session [" + sessionToUse + "]"); } listener.OnMessage(message, sessionToUse); // Clean up specially exposed Session, if any if (sessionToUse != session) { if (sessionToUse.Transacted && SessionTransacted) { // Transacted session created by this container -> commit. EmsUtils.CommitIfNecessary(sessionToUse); } } } finally { EmsUtils.CloseSession(sessionToClose); EmsUtils.CloseConnection(conToClose); } }
/// <summary> /// Invokes the specified listener: either as standard EMS MessageListener /// or (preferably) as Spring ISessionAwareMessageListener. /// </summary> /// <param name="session">The session to operate on.</param> /// <param name="message">The received message.</param> /// <exception cref="EMSException">If thrown by EMS API methods.</exception> /// <see cref="MessageListener"/> protected virtual void InvokeListener(ISession session, Message message) { object listener = MessageListener; if (listener is ISessionAwareMessageListener) { DoInvokeListener((ISessionAwareMessageListener) listener, session, message); } else if (listener is IMessageListener) { DoInvokeListener((IMessageListener)listener, message); } else if (listener != null) { throw new ArgumentException("Only MessageListener and ISessionAwareMessageListener supported"); } else { throw new InvalidOperationException("No message listener specified - see property MessageListener"); } }
/// <summary> /// Executes the specified listener, /// committing or rolling back the transaction afterwards (if necessary). /// </summary> /// <param name="session">The session to operate on.</param> /// <param name="message">The received message.</param> /// <exception cref="EMSException">If thrown by EMS API methods.</exception> /// <see cref="InvokeListener"/> /// <see cref="CommitIfNecessary"/> /// <see cref="RollbackOnExceptionIfNecessary"/> protected virtual void DoExecuteListener(ISession session, Message message) { if (!AcceptMessagesWhileStopping && !IsRunning) { #region Logging if (logger.IsWarnEnabled) { logger.Warn("Rejecting received message because of the listener container " + "having been stopped in the meantime: " + message); } #endregion RollbackIfNecessary(session); throw new MessageRejectedWhileStoppingException(); } try { InvokeListener(session, message); } catch (Exception ex) { RollbackOnExceptionIfNecessary(session, ex); throw; } CommitIfNecessary(session, message); }
/// <summary> /// Sends the specified message. /// </summary> /// <param name="message">The message.</param> public void Send(Message message) { target.Send(message, this.deliveryMode, this.priority, this.timeToLive); }
public void Send(Destination destination, Message message) { throw new NotImplementedException(); }
/// <summary> /// Post-process the given message producer before using it to send the response. /// The default implementation is empty. /// </summary> /// <param name="producer">The producer that will be used to send the message.</param> /// <param name="response">The outgoing message about to be sent.</param> protected virtual void PostProcessProducer(IMessageProducer producer, Message response) { }
public void Send(Message message, int deliveryMode, int priority, long timeToLive) { throw new NotImplementedException(); }
public void OnMessage(Message message) { bool exposeResource = container.ExposeListenerSession; if (exposeResource) { TransactionSynchronizationManager.BindResource( container.ConnectionFactory, new LocallyExposedEmsResourceHolder(session)); } try { container.ExecuteListener(session, message); } finally { if (exposeResource) { TransactionSynchronizationManager.UnbindResource(container.ConnectionFactory); } } }
public void Send(Destination dest, Message message, MessageDeliveryMode deliveryMode, int priority, long timeToLive) { throw new NotImplementedException(); }
public void OnMessage(Message message, ISession session) { throw exception; }
public void OnMessage(Message message) { this.message = "Test1"; }
/// <summary> /// Invoke the specified listener as standard JMS MessageListener. /// </summary> /// <remarks>Default implementation performs a plain invocation of the /// <code>OnMessage</code> methods</remarks> /// <param name="listener">The listener to invoke.</param> /// <param name="message">The received message.</param> /// <exception cref="EMSException">if thrown by the EMS API methods</exception> protected virtual void DoInvokeListener(IMessageListener listener, Message message) { listener.OnMessage(message); }
/// <summary> Actually send the given EMS message.</summary> /// <param name="producer">the EMS MessageProducer to send with /// </param> /// <param name="message">the EMS Message to send /// </param> /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception> protected virtual void DoSend(IMessageProducer producer, Message message) { if (ExplicitQosEnabled) { producer.Send(message, DeliveryMode, Priority, TimeToLive); } else { producer.Send(message); } }