//收到資料要做的事 private void synTopicSubscriber_OnMessageReceived(Apache.NMS.ITextMessage message) { string jsonString = message.Text; log.Debug("接收到MQ的訊息: " + jsonString); this.waitForWork.Enqueue(jsonString);//塞入Queue }
private bool DoSend(Apache.NMS.ITextMessage textMessage, out Exception exception) { exception = null; try { this.InitializeIfReq(); this.messageProducer.Send(textMessage); this.queueingTransportLogger.LogMessageWasSent(textMessage.GetId(), textMessage.GetMessageType(), textMessage.GetTryIndex(), textMessage.GetSentDate(), textMessage.GetDeliveryDelay(), textMessage.Text); } catch (Apache.NMS.NMSConnectionException exc) { exception = new QueueingException("Cannot send a message due to connection problems", exc); } catch (Apache.NMS.ActiveMQ.ConnectionClosedException exc) { exception = new QueueingException("Cannot send the message due to connection problem", exc); } catch (Apache.NMS.ActiveMQ.BrokerException exc) { exception = new QueueingException(string.Format("Broker exception happened while sending the message: {0}\r\n", textMessage.Text), exc); } catch (Apache.NMS.NMSException exc) { exception = new QueueingException(string.Format("Cannot send the message with text: {0}\r\n", textMessage.Text), exc); } return(exception == null); }
public static IMessage CreateFrom(Apache.NMS.IMessage queueMessage, ISession session) { if (queueMessage == null) { return(null); } Apache.NMS.ITextMessage textMessage = queueMessage as Apache.NMS.ITextMessage; if (textMessage == null) { throw new ArgumentException(string.Format("Unsupported message type provided: \"{0}\"", queueMessage.GetType().FullName)); } Message message = new Message(); message.queueMessage = queueMessage; message.Text = textMessage.Text; message.Id = textMessage.GetId(); message.Type = textMessage.GetMessageType(); message.SentDate = textMessage.GetSentDate(); message.TryIndex = textMessage.GetTryIndex(); message.DeliveryTimeout = textMessage.GetDeliveryDelay(); message.session = session; return(message); }
protected void LogMessageReceived(Apache.NMS.IMessage message) { Apache.NMS.ITextMessage textMessage = message as Apache.NMS.ITextMessage; if (textMessage != null) { this.logger.LogMessageWasReceived(textMessage.GetId(), textMessage.GetMessageType(), textMessage.GetTryIndex(), textMessage.GetSentDate(), textMessage.GetDeliveryDelay(), textMessage.Text); } }
public void Send(IMessage message) { int tryIndex = 0; Exception exception; this.InitializeIfReq(); Apache.NMS.ITextMessage textMessage = this.session.CreateMessage(message, this.queue.MessageTimeToLive); bool isSendingSuccessfull = this.DoSend(textMessage, out exception); if (isSendingSuccessfull) { return; } this.log.InfoFormat("Message couldn't be sent from the first try. Message.Id = {0}", textMessage.GetId()); if (!this.queue.GuaranteeDelivery) { this.log.Info("Guaranteed delivery is disabled. Throwing an exception..."); throw exception; } while (tryIndex < this.queue.GuaranteedDeliveryTriesCount) { tryIndex++; this.log.InfoFormat("Starting sending try index {0} for Message.Id = {1}...", tryIndex, textMessage.GetId()); this.log.InfoFormat("Closing internal producers"); this.CloseProducer(); this.log.InfoFormat("Gaving the broker a chance to recover. Sleeping for 1 second"); Thread.Sleep(1000); isSendingSuccessfull = this.DoSend(textMessage, out exception); if (isSendingSuccessfull) { this.log.InfoFormat("Sending try index {0} for Message.Id = {1} succeeded.", tryIndex, textMessage.GetId()); return; } this.log.InfoFormat("Sending with try index {0} for Message.Id = {1} failed.", tryIndex, textMessage.GetId()); } this.log.InfoFormat("Delivery try count limit of {0} tries is reached for Message.Id = {1}.", this.queue.GuaranteedDeliveryTriesCount, textMessage.GetId()); if (exception != null) { this.log.InfoFormat("Throw exception for resending of Message.Id = {0}.", textMessage.GetId()); throw exception; } }
public void Listner_eventMsg(ActivMQListner l, Apache.NMS.ITextMessage msg) { //Console.WriteLine(msg.Text); //viewModel.ListTrains[0].Destination = msg.Text; // Désérialiser => Récupérer dans un objet train dans le mainviewmodel Train myTrain = SerialisationTool.deserialiser(msg.Text); // L'envoyer dans le MainViewModel avec la fonction Add Console.WriteLine(msg.Text); viewModel.AddTrain(myTrain); }