public void TestBroserIteratively() { using (IConnection connection = CreateConnection()) using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) { connection.Start(); IQueue queue = session.CreateTemporaryQueue(); // enqueue a message using (IMessageProducer producer = session.CreateProducer(queue)) { IMessage message = producer.CreateMessage(); producer.Send(message); } Thread.Sleep(2000); // browse queue several times for (int j = 0; j < 1000; j++) { using (QueueBrowser browser = session.CreateBrowser(queue) as QueueBrowser) { Tracer.DebugFormat("Running Iterative QueueBrowser sample #{0}", j); IEnumerator enumeration = browser.GetEnumerator(); Assert.IsTrue(enumeration.MoveNext(), "should have received the second message"); } } } }
protected void SendMessage(IMessageProducer producer) { IMessage request = producer.CreateMessage(); request.NMSType = "Test"; producer.Send(request); }
private void AckownlageMessage(IMessage message) { var ack = producer.CreateMessage(); ack.NMSType = MessageType.Affirmation.ToString(); producer.Send(message.NMSReplyTo, ack); }
public void TestCannotSendOnDeletedTemporaryTopic() { try { using (IConnection connection = GetConnection("c1")) using (IDestination destination = GetDestination("temp1")) using (IMessageProducer producer = GetProducer("sender")) { ITemporaryTopic tempTopic = destination as ITemporaryTopic; Assert.NotNull(tempTopic, "Failed to Create Temporary Topic."); IMessage msg = producer.CreateMessage(); tempTopic.Delete(); try { producer.Send(msg); Assert.Fail("Expected Exception for sending message on deleted temporary topic."); } catch (NMSException nex) { Assert.IsTrue(nex is InvalidDestinationException, "Received Unexpected exception {0}", nex); } } } catch (Exception ex) { this.PrintTestFailureAndAssert(GetTestMethodName(), "Unexpected exception.", ex); } }
protected void SendMessage(IMessageProducer producer) { IMessage request = producer.CreateMessage(); request.NMSCorrelationID = CORRELATION_ID; request.NMSType = "Test"; producer.Send(request); }
public string SendMessage(string message) { string result = string.Empty; try { ITopic destination = _session.GetTopic("events"); using (IMessageProducer producer = _session.CreateProducer(destination)) { producer.DeliveryMode = MsgDeliveryMode.Persistent; producer.TimeToLive = TimeSpan.FromHours(1); //var textMessage = producer.CreateTextMessage(message); //producer.Send(textMessage); var myMessage = producer.CreateMessage(); myMessage.NMSMessageId = Guid.NewGuid().ToString(); myMessage.NMSDeliveryMode = MsgDeliveryMode.Persistent; myMessage.NMSPriority = MsgPriority.Normal; myMessage.NMSTimeToLive = TimeSpan.FromMinutes(15); producer.DeliveryMode = MsgDeliveryMode.Persistent; producer.Send(myMessage); } result = "Message sent successfully."; } catch (Exception ex) { result = ex.Message; Console.WriteLine(ex.ToString()); } return(result); }
public async Task ConsumeInTwoThreads() { ParameterizedThreadStart threadStart = delegate(object o) { IMessageConsumer consumer = (IMessageConsumer)o; IMessage message = consumer.Receive(TimeSpan.FromSeconds(2)); Assert.IsNotNull(message); }; using (IConnection connection = CreateConnection(TEST_CLIENT_ID)) { await connection.StartAsync(); using (ISession session = await connection.CreateSessionAsync(AcknowledgementMode.Transactional)) { IQueue queue = SessionUtil.GetDestination(session, DESTINATION_NAME) as IQueue; // enqueue 2 messages using (IMessageConsumer consumer = await session.CreateConsumerAsync(queue)) using (IMessageProducer producer = await session.CreateProducerAsync(queue)) { producer.DeliveryMode = MsgDeliveryMode.Persistent; await producer.SendAsync(producer.CreateMessage()); await producer.SendAsync(producer.CreateMessage()); await session.CommitAsync(); // receive first using a dedicated thread. This works Thread thread = new Thread(threadStart); thread.Start(consumer); thread.Join(); await session.CommitAsync(); // receive second using main thread. This FAILS IMessage message = await consumer.ReceiveAsync(TimeSpan.FromSeconds(2)); // throws System.Threading.AbandonedMutexException Assert.IsNotNull(message); await session.CommitAsync(); } } } }
public IMessage CreateMessage() { Used?.Invoke(); return(_producer.CreateMessage()); }
/// <summary> /// Creates the message. /// </summary> /// <returns>A new message</returns> public IMessage CreateMessage() { return(target.CreateMessage()); }