/// <summary> /// Initializes a new instance of the <see cref="CachedMessageProducer"/> class. /// </summary> /// <param name="target">The target.</param> public CachedMessageProducer(IMessageProducer target) { this.target = target; this.msgDeliveryMode = target.DeliveryMode; this.priority = target.Priority; this.timeToLive = target.TimeToLive; }
public void ProducerCallbackWithIdAndTimestampDisabled() { NmsTemplate template = CreateTemplate(); template.ConnectionFactory = mockConnectionFactory; template.MessageIdEnabled = false; template.MessageTimestampEnabled = false; IMessageProducer mockProducer = mocks.StrictMock <IMessageProducer>(); Expect.Call(mockSession.CreateProducer(null)).Return(mockProducer); mockProducer.DisableMessageID = true; LastCall.On(mockProducer).Repeat.Once(); mockProducer.DisableMessageTimestamp = true; LastCall.On(mockProducer).Repeat.Once(); Expect.Call(mockProducer.Priority).Return(MsgPriority.Normal); CloseProducerSessionConnection(mockProducer); mocks.ReplayAll(); template.Execute((session, producer) => { bool b = session.Transacted; MsgPriority priority = producer.Priority; return(null); }); mocks.VerifyAll(); }
//P2P模式,一个生产者对应一个消费者 private bool P2P(string message, MsgPriority priority) { try { if (hasSelector) { //设置消息对象的属性,这个很重要,是Queue的过滤条件,也是P2P消息的唯一指定属性 msg.Properties.SetString("filter", "demo"); //P2P模式 } prod.Priority = priority; //设置持久化 prod.DeliveryMode = MsgDeliveryMode.Persistent; //生产者把消息发送出去,几个枚举参数MsgDeliveryMode是否持久化,MsgPriority消息优先级别,存活时间,当然还有其他重载 prod.Send(msg, MsgDeliveryMode.Persistent, priority, TimeSpan.MinValue); } catch (System.Exception e) { sendSuccess = false; Console.WriteLine("Exception:{0}", e.Message); Console.ReadLine(); throw e; } return(sendSuccess); }
public bool SendMessage(string message, string msgId = "defult", MsgPriority priority = MsgPriority.Normal) { if (prod == null) { sendSuccess = false; Console.WriteLine("call InitQueueOrTopic() first!!"); return(false); } Console.WriteLine("Begin send messages..."); //给这个对象赋实际的消息 msg.NMSCorrelationID = msgId; msg.Properties["MyID"] = msgId; msg.NMSMessageId = msgId; msg.Text = message; Console.WriteLine(message); if (isTopic) { sendSuccess = ProducerSubcriber(message, priority); } else { sendSuccess = P2P(message, priority); } return(sendSuccess); }
public void ProducerCallback() { NmsTemplate template = CreateTemplate(); template.ConnectionFactory = mockConnectionFactory; IMessageProducer mockProducer = mocks.StrictMock <IMessageProducer>(); Expect.Call(mockSession.CreateProducer(null)).Return(mockProducer); Expect.Call(mockProducer.Priority).Return(MsgPriority.Normal); CloseProducerSessionConnection(mockProducer); mocks.ReplayAll(); MsgPriority priority = MsgPriority.Highest; template.Execute((session, producer) => { bool b = session.Transacted; priority = producer.Priority; return(null); }); Assert.AreEqual(priority, MsgPriority.Normal); mocks.VerifyAll(); }
public Producer(ISession session, IDestination dest, int count, MsgPriority priority) { this.session = session; this.dest = dest; this.count = count; this.priority = priority; }
/// <summary> /// 发送消息 /// </summary> /// <param name="message"></param> /// <param name="msgId"></param> /// <param name="priority"></param> /// <returns></returns> public bool SendMessage(string message, string msgId = "defult", MsgPriority priority = MsgPriority.Normal) { bool sendSuccess = false; if (_prod == null) { //引发事件 _eventSource.RaiseErroeMsgEvent(this.BusinessName, "call InitQueueOrTopic() first!!!"); return(sendSuccess); } Console.WriteLine("Begin send messages..."); //给这个对象赋实际的消息 _textMessage.NMSCorrelationID = msgId; _textMessage.Properties["MyID"] = msgId; _textMessage.NMSMessageId = msgId; _textMessage.Text = message; if (_isTopic) { sendSuccess = this.ProducerSubcriber(message, priority); } else { sendSuccess = this.P2P(message, priority); } return(sendSuccess); }
private InboundMessageDispatch CreateEnvelope(MsgPriority priority = MsgPriority.BelowNormal) { InboundMessageDispatch envelope = new InboundMessageDispatch(); envelope.Message = CreateMessage(priority); return(envelope); }
public void ProducerCallbackWithIdAndTimestampDisabled() { NmsTemplate template = CreateTemplate(); template.ConnectionFactory = mockConnectionFactory; template.MessageIdEnabled = false; template.MessageTimestampEnabled = false; IMessageProducer mockProducer = A.Fake <IMessageProducer>(); A.CallTo(() => mockSession.CreateProducer(null)).Returns(mockProducer); A.CallTo(() => mockProducer.Priority).Returns(MsgPriority.Normal); template.Execute((session, producer) => { bool b = session.Transacted; MsgPriority priority = producer.Priority; return(null); }); AssertCloseProducerSessionConnection(mockProducer); A.CallToSet(() => mockProducer.DisableMessageID).WhenArgumentsMatch(x => x.Get <bool>(0) == true).MustHaveHappenedOnceExactly(); A.CallToSet(() => mockProducer.DisableMessageTimestamp).WhenArgumentsMatch(x => x.Get <bool>(0) == true).MustHaveHappenedOnceExactly(); }
/// <summary> /// P2P模式,一个生产者对应一个消费者 /// </summary> /// <param name="message"></param> /// <param name="priority"></param> /// <returns></returns> private bool P2P(string message, MsgPriority priority) { bool sendSuccess = true; try { if (_hasSelector) { //设置消息对象的属性,这个很重要,是Queue的过滤条件,也是P2P消息的唯一指定属性 _textMessage.Properties.SetString("filter", "demo"); //P2P模式 } _prod.Priority = priority; //设置持久化 _prod.DeliveryMode = MsgDeliveryMode.Persistent; //生产者把消息发送出去,几个枚举参数MsgDeliveryMode是否持久化,MsgPriority消息优先级别,存活时间,当然还有其他重载 _prod.Send(_textMessage, MsgDeliveryMode.Persistent, priority, TimeSpan.MinValue); } catch (Exception e) { sendSuccess = false; //引发事件 _eventSource.RaiseErroeMsgEvent(this.BusinessName, e.Message); } return(sendSuccess); }
public void TestCopy() { this.nmsMessageID = "ID:1141:45278:429"; this.nmsCorrelationID = "testcorrelationid"; this.nmsDestination = new ActiveMQTopic("test.topic"); this.nmsReplyTo = new ActiveMQTempTopic("test.replyto.topic:001"); this.nmsDeliveryMode = MsgDeliveryMode.NonPersistent; this.nmsType = "test type"; this.nmsPriority = MsgPriority.High; this.nmsTimestamp = DateTime.Now; ActiveMQMessage msg1 = new ActiveMQMessage(); msg1.NMSMessageId = this.nmsMessageID; msg1.NMSCorrelationID = this.nmsCorrelationID; msg1.FromDestination = this.nmsDestination; msg1.NMSReplyTo = this.nmsReplyTo; msg1.NMSDeliveryMode = this.nmsDeliveryMode; msg1.NMSType = this.nmsType; msg1.NMSPriority = this.nmsPriority; msg1.NMSTimestamp = this.nmsTimestamp; msg1.ReadOnlyProperties = true; ActiveMQMessage msg2 = msg1.Clone() as ActiveMQMessage; Assert.IsTrue(msg1.NMSMessageId.Equals(msg2.NMSMessageId)); Assert.IsTrue(msg1.NMSCorrelationID.Equals(msg2.NMSCorrelationID)); Assert.IsTrue(msg1.NMSDestination.Equals(msg2.NMSDestination)); Assert.IsTrue(msg1.NMSReplyTo.Equals(msg2.NMSReplyTo)); Assert.IsTrue(msg1.NMSDeliveryMode == msg2.NMSDeliveryMode); Assert.IsTrue(msg1.NMSRedelivered == msg2.NMSRedelivered); Assert.IsTrue(msg1.NMSType.Equals(msg2.NMSType)); Assert.IsTrue(msg1.NMSPriority == msg2.NMSPriority); Assert.IsTrue(msg1.NMSTimestamp == msg2.NMSTimestamp); }
// Message priorities are defined as follows : // | MSMQ | NMS | // | MessagePriority | MsgPriority | // +--------------------+--------------------+ // | Lowest | Lowest | // | VeryLow | VeryLow | // | Low | Low | // | \-> | AboveLow | // | /-> | BelowNormal | // | Normal | Normal | // | AboveNormal | AboveNormal | // | High | High | // | VeryHigh | VeryHigh | // | Highest | Highest | // +--------------------+--------------------+ /// <summary> /// Converts the specified NMS message priority to an equivalent MSMQ /// message priority. /// </summary> /// <param name="msgPriority">NMS message priority to be converted.</param> /// <result>Converted MSMQ message priority.</result> private static MessagePriority ToMsmqMessagePriority(MsgPriority msgPriority) { switch (msgPriority) { case MsgPriority.Lowest: return(MessagePriority.Lowest); case MsgPriority.VeryLow: return(MessagePriority.VeryLow); case MsgPriority.Low: case MsgPriority.AboveLow: return(MessagePriority.Low); default: case MsgPriority.BelowNormal: case MsgPriority.Normal: return(MessagePriority.Normal); case MsgPriority.AboveNormal: return(MessagePriority.AboveNormal); case MsgPriority.High: return(MessagePriority.High); case MsgPriority.VeryHigh: return(MessagePriority.VeryHigh); case MsgPriority.Highest: return(MessagePriority.Highest); } }
private NmsMessage CreateMessage(MsgPriority priority) { NmsTestMessageFacade facade = new NmsTestMessageFacade(); facade.NMSPriority = priority; facade.NMSMessageId = messageId.generateID(); return(new NmsMessage(facade)); }
public static byte GetValueForPriority(MsgPriority mp) { if ((int)mp > 9) { mp = MsgPriority.Highest; } return(Convert.ToByte((int)mp)); }
/// <summary> /// Sets the priority of a message sent to the broker /// </summary> /// <param name="context"></param> /// <param name="priority"></param> public static void SetPriority(this SendContext context, MsgPriority priority) { if (!context.TryGetPayload(out ActiveMqSendContext sendContext)) { throw new ArgumentException("The ActiveMqSendContext was not available"); } sendContext.Priority = priority; }
/// <summary> /// Sets the priority of a message sent to the broker /// </summary> /// <param name="context"></param> /// <param name="priority"></param> public static bool TrySetPriority(this SendContext context, MsgPriority priority) { if (!context.TryGetPayload(out ActiveMqSendContext sendContext)) { return(false); } sendContext.Priority = priority; return(true); }
/// <summary> /// Sends the message to the default destination with the explicit QoS configuration /// </summary> public void Send(Apache.NMS.IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) { Apache.NMS.EMS.Message msg = (Apache.NMS.EMS.Message)message; this.tibcoMessageProducer.Send( msg.tibcoMessage, EMSConvert.ToMessageDeliveryMode(deliveryMode), (int)priority, (long)timeToLive.TotalMilliseconds); }
public PooledProducer(IMessageProducer producer, IDestination destination) { this.producer = producer; this.destination = destination; this.deliveryMode = producer.DeliveryMode; this.disableMessageID = producer.DisableMessageID; this.disableMessageTimestamp = producer.DisableMessageTimestamp; this.priority = producer.Priority; this.timeToLive = producer.TimeToLive; }
public static MsgPriority GetPriorityFromValue(byte value) { if (value > 9) { value = 9; } MsgPriority result = NMSConstants.defaultPriority; switch (value) { case 0x00: result = MsgPriority.Lowest; break; case 0x01: result = MsgPriority.VeryLow; break; case 0x02: result = MsgPriority.Low; break; case 0x03: result = MsgPriority.AboveLow; break; case 0x04: result = MsgPriority.BelowNormal; break; case 0x05: result = MsgPriority.Normal; break; case 0x06: result = MsgPriority.AboveNormal; break; case 0x07: result = MsgPriority.High; break; case 0x08: result = MsgPriority.VeryHigh; break; case 0x09: result = MsgPriority.Highest; break; } return(result); }
public void Send(IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) { this.ThrowIfClosed(); if (Destination == null) { throw new IllegalStateException("Can not Send message on Anonymous Producer (without Destination)."); } if (message == null) { throw new IllegalStateException("Can not Send a null message."); } DoSend(Destination, message, deliveryMode, priority, timeToLive); }
public void Send(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) { if (destination == null) { destination = this.destination; } IMessageProducer producer = this.MessageProducer; lock(producer) { producer.Send(destination, message, deliveryMode, priority, timeToLive); } }
public BaseMessage(BaseMessage copy) { this.propertiesMap = copy.propertiesMap; this.destination = copy.destination; this.correlationId = copy.correlationId; this.timeToLive = copy.timeToLive; this.messageId = copy.messageId; this.deliveryMode = copy.deliveryMode; this.priority = copy.priority; this.replyTo = copy.replyTo; this.content = copy.content; this.type = copy.type; this.Acknowledger = copy.Acknowledger; this.timestamp = copy.timestamp; this.readOnlyMsgBody = copy.readOnlyMsgBody; }
private MsgPriority GetMsgPriority(QuqueName command) { MsgPriority priority = MsgPriority.Normal; switch (command) { case QuqueName.BusinessProcessing: priority = MsgPriority.High; break; case QuqueName.ClientHeart: case QuqueName.StoreReportData: priority = MsgPriority.Normal; break; } return(priority); }
/// <summary> /// Sends the message to the default destination with the explicit QoS configuration /// </summary> public void Send(Apache.NMS.IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) { Apache.NMS.EMS.Message msg = GetEMSMessage(message); try { this.tibcoMessageProducer.Send( msg.tibcoMessage, EMSConvert.ToMessageDeliveryMode(deliveryMode), (int)priority, (long)timeToLive.TotalMilliseconds); } catch (Exception ex) { ExceptionUtil.WrapAndThrowNMSException(ex); } }
public virtual void SetUp() { this.nmsMessageID = "testid"; this.nmsCorrelationID = "testcorrelationid"; this.nmsDestination = new ActiveMQTopic("TEST.test.topic"); this.nmsReplyTo = new ActiveMQTempTopic("TEST.test.replyto.topic:001"); this.nmsDeliveryMode = MsgDeliveryMode.NonPersistent; this.nmsRedelivered = true; this.nmsType = "test type"; this.nmsPriority = MsgPriority.High; this.nmsTimestamp = DateTime.Now; this.consumerIDs = new long[3]; for (int i = 0; i < this.consumerIDs.Length; i++) { this.consumerIDs[i] = i; } }
public virtual void SetUp() { this.nmsMessageID = "testid"; this.nmsCorrelationID = "testcorrelationid"; this.nmsDestination = new ActiveMQTopic("test.topic"); this.nmsReplyTo = new ActiveMQTempTopic("test.replyto.topic:001"); this.nmsDeliveryMode = MsgDeliveryMode.NonPersistent; this.nmsRedelivered = true; this.nmsType = "test type"; this.nmsPriority = MsgPriority.High; this.nmsTimestamp = DateTime.Now; this.consumerIDs = new long[3]; for(int i = 0; i < this.consumerIDs.Length; i++) { this.consumerIDs[i] = i; } }
//发布订阅模式,一个生产者多个消费者 private bool ProducerSubcriber(string message, MsgPriority priority) { try { prod.Priority = priority; //设置持久化,如果DeliveryMode没有设置或者设置为NON_PERSISTENT,那么重启MQ之后消息就会丢失 prod.DeliveryMode = MsgDeliveryMode.Persistent; prod.Send(msg, Apache.NMS.MsgDeliveryMode.Persistent, priority, TimeSpan.MinValue); //System.Threading.Thread.Sleep(1000); } catch (System.Exception e) { sendSuccess = false; Console.WriteLine("Exception:{0}", e.Message); Console.ReadLine(); throw e; } return(sendSuccess); }
/// <summary> /// 发布订阅模式,一个生产者多个消费者 /// </summary> /// <param name="message"></param> /// <param name="priority"></param> /// <returns></returns> private bool ProducerSubcriber(string message, MsgPriority priority) { bool sendSuccess = true; try { _prod.Priority = priority; //设置持久化,如果DeliveryMode没有设置或者设置为NON_PERSISTENT,那么重启MQ之后消息就会丢失 _prod.DeliveryMode = MsgDeliveryMode.Persistent; _prod.Send(_textMessage, MsgDeliveryMode.Persistent, priority, TimeSpan.MinValue); //System.Threading.Thread.Sleep(1000); } catch (Exception e) { sendSuccess = false; //引发事件 _eventSource.RaiseErroeMsgEvent(this.BusinessName, e.Message); } return(sendSuccess); }
public void ProducerCallback() { NmsTemplate template = CreateTemplate(); template.ConnectionFactory = mockConnectionFactory; IMessageProducer mockProducer = A.Fake <IMessageProducer>(); A.CallTo(() => mockSession.CreateProducer(null)).Returns(mockProducer); A.CallTo(() => mockProducer.Priority).Returns(MsgPriority.Normal); MsgPriority priority = MsgPriority.Highest; template.Execute((session, producer) => { bool b = session.Transacted; priority = producer.Priority; return(null); }); Assert.AreEqual(priority, MsgPriority.Normal); AssertCloseProducerSessionConnection(mockProducer); }
/// <summary> /// Sends the message to the given destination with the explicit QoS /// configuration. /// </summary> public void Send(Apache.NMS.IDestination destination, Apache.NMS.IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) { Apache.NMS.XMS.Destination dest = (Apache.NMS.XMS.Destination)destination; Apache.NMS.XMS.Message msg = GetXMSMessage(message); try { this.xmsMessageProducer.Send( dest.xmsDestination, msg.xmsMessage, XMSConvert.ToJMSDeliveryMode(deliveryMode), (int)priority, (long)timeToLive.TotalMilliseconds); } catch (Exception ex) { ExceptionUtil.WrapAndThrowNMSException(ex); } }
// private static byte ToAmqpMessagePriority(MsgPriority msgPriority) { return (byte)msgPriority; }
/// <summary> /// Sends the message to the given destination with the explicit QoS configuration. The object must be serializable to XML. /// </summary> public static void Send(this IMessageProducer producer, IDestination destination, object objMessage, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) { producer.Send(destination, producer.CreateXmlMessage(objMessage), deliveryMode, priority, timeToLive); }
/// <summary> /// Sends the message to the default destination with the explicit QoS configuration. The object must be serializable to XML. /// </summary> public static void Send(this IMessageProducer producer, object objMessage, Encoding encoding, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) { producer.Send(producer.CreateXmlMessage(objMessage, encoding), deliveryMode, priority, timeToLive); }
/// <summary> /// Sends a message to the specified message. /// </summary> /// <param name="message">The message to send.</param> /// <param name="deliveryMode">The QOS to use for sending <see cref="msgDeliveryMode"/>.</param> /// <param name="priority">The message priority.</param> /// <param name="timeToLive">The time to live.</param> public void Send(IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) { target.Send(message, deliveryMode, priority, timeToLive); }
public void SendRequest(IMessage message, MsgDeliveryMode deliveryMode, MsgPriority messagePriority, TimeSpan timeToLive) { this.producer.Send(message, deliveryMode, messagePriority, timeToLive); }
public void SendRequest(Destination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority messagePriority, TimeSpan timeToLive) { if (!this.isInitialized) this.asr.WaitOne(10000); this.producer.Send(destination.GetDestination(this.session), message, deliveryMode, messagePriority, timeToLive); }
public void Send(string message, MsgPriority priority, params KeyValuePair<string, object>[] parameters) { var request = Session.CreateTextMessage(message); request.NMSPriority = priority; foreach (var pair in parameters) { switch (pair.Value.GetType().Name) { case "string": request.Properties.SetString(pair.Key, pair.Value as string); break; case "long": request.Properties.SetLong(pair.Key, (long)pair.Value); break; case "int32": request.Properties.SetInt(pair.Key, (int)pair.Value); break; } } _producer.Send(request); }
public void Send(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) { try { if (this.ProducerTransformer != null) { IMessage transformed = this.ProducerTransformer(this.session, this, message); if (transformed != null) { message = transformed; } } message.NMSDeliveryMode = deliveryMode; message.NMSTimeToLive = timeToLive; message.NMSPriority = priority; if (!DisableMessageTimestamp) { message.NMSTimestamp = DateTime.UtcNow; } if (!DisableMessageID) { // TODO: message.NMSMessageId = } // Convert the Message into a Amqp message Message msg = session.MessageConverter.ToAmqpMessage(message); qpidSender.Send(msg); } catch (Exception e) { throw new NMSException(e.Message + ": " /* TODO: + dest */, e); } }
public static void SingleSend(string message, MsgPriority priority, params KeyValuePair<string, object>[] parameters) { using (var queue = new Queue()) { queue.Send(message, priority, parameters); } }
protected void Send(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive, bool specifiedTimeToLive) { if(null == destination) { // See if this producer was created without a destination. if(null == info.Destination) { throw new NotSupportedException(); } // The producer was created with a destination, but an invalid destination // was specified. throw new Apache.NMS.InvalidDestinationException(); } ActiveMQDestination dest = null; if(destination == this.info.Destination) { dest = destination as ActiveMQDestination; } else if(info.Destination == null) { dest = ActiveMQDestination.Transform(destination); } else { throw new NotSupportedException("This producer can only send messages to: " + this.info.Destination.PhysicalName); } if(this.ProducerTransformer != null) { IMessage transformed = this.ProducerTransformer(this.session, this, message); if(transformed != null) { message = transformed; } } ActiveMQMessage activeMessage = this.messageTransformation.TransformMessage<ActiveMQMessage>(message); activeMessage.ProducerId = info.ProducerId; activeMessage.Destination = dest; activeMessage.NMSDeliveryMode = deliveryMode; activeMessage.NMSPriority = priority; // Always set the message Id regardless of the disable flag. MessageId id = new MessageId(); id.ProducerId = info.ProducerId; id.ProducerSequenceId = Interlocked.Increment(ref this.producerSequenceId); activeMessage.MessageId = id; if(!disableMessageTimestamp) { activeMessage.NMSTimestamp = DateTime.UtcNow; } if(specifiedTimeToLive) { activeMessage.NMSTimeToLive = timeToLive; } // Ensure there's room left to send this message if(this.usage != null) { usage.WaitForSpace(); } lock(closedLock) { if(closed) { throw new ConnectionClosedException(); } session.DoSend(activeMessage, this, this.usage, this.RequestTimeout); } }
public void Send(IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) { Send(destination, message, deliveryMode, priority, timeToLive); }
public void Send(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) { throw new NotImplementedException(); }
public static void Send(this IMessage message, IMessageProducer producer, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) { producer.Send(message, deliveryMode, priority, timeToLive); }