Skip to content
Permalink
Browse files
Sample to show convention of new "using" syntax for Destinations.
  • Loading branch information
Jim Gomes committed Oct 8, 2014
1 parent 704a2f5 commit da1b979a9188f67aadda1dda67aeef8c270bb958
Showing 1 changed file with 77 additions and 90 deletions.
@@ -36,7 +36,7 @@ public override void SetUp()
semaphore = new AutoResetEvent(false);
received = false;
receivedMsg = null;

RESPONSE_CLIENT_ID = GetTestClientId() + ":RESPONSE";
}

@@ -56,22 +56,20 @@ public override void TearDown()
{
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
using(IDestination destination = CreateDestination(session, DestinationType.Queue))
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
IDestination destination = CreateDestination(session, DestinationType.Queue);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
producer.DeliveryMode = deliveryMode;
consumer.Listener += new MessageListener(OnMessage);
producer.DeliveryMode = deliveryMode;
consumer.Listener += new MessageListener(OnMessage);

IMessage request = session.CreateMessage();
request.NMSCorrelationID = "AsyncConsume";
request.NMSType = "Test";
producer.Send(request);
IMessage request = session.CreateMessage();
request.NMSCorrelationID = "AsyncConsume";
request.NMSType = "Test";
producer.Send(request);

WaitForMessageToArrive();
Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID.");
}
WaitForMessageToArrive();
Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID.");
}
}
}
@@ -85,23 +83,21 @@ public override void TearDown()
{
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
using(IDestination destination = CreateDestination(session, DestinationType.Queue))
using(IMessageProducer producer = session.CreateProducer(destination))
{
IDestination destination = CreateDestination(session, DestinationType.Queue);
using(IMessageProducer producer = session.CreateProducer(destination))
{
producer.DeliveryMode = deliveryMode;
producer.DeliveryMode = deliveryMode;

IMessage request = session.CreateMessage();
request.NMSCorrelationID = "AsyncConsumeAfterSend";
request.NMSType = "Test";
producer.Send(request);
IMessage request = session.CreateMessage();
request.NMSCorrelationID = "AsyncConsumeAfterSend";
request.NMSType = "Test";
producer.Send(request);

using(IMessageConsumer consumer = session.CreateConsumer(destination))
{
consumer.Listener += new MessageListener(OnMessage);
WaitForMessageToArrive();
Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID.");
}
using(IMessageConsumer consumer = session.CreateConsumer(destination))
{
consumer.Listener += new MessageListener(OnMessage);
WaitForMessageToArrive();
Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID.");
}
}
}
@@ -116,23 +112,21 @@ public override void TearDown()
{
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
using(IDestination destination = CreateDestination(session, DestinationType.Queue))
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
IDestination destination = CreateDestination(session, DestinationType.Queue);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
producer.DeliveryMode = deliveryMode;
producer.DeliveryMode = deliveryMode;

IMessage request = session.CreateMessage();
request.NMSCorrelationID = "AsyncConsumeAfterSendLateListener";
request.NMSType = "Test";
producer.Send(request);
IMessage request = session.CreateMessage();
request.NMSCorrelationID = "AsyncConsumeAfterSendLateListener";
request.NMSType = "Test";
producer.Send(request);

// now lets add the listener
consumer.Listener += new MessageListener(OnMessage);
WaitForMessageToArrive();
Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID.");
}
// now lets add the listener
consumer.Listener += new MessageListener(OnMessage);
WaitForMessageToArrive();
Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID.");
}
}
}
@@ -146,28 +140,26 @@ public override void TearDown()
{
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
using(IDestination destination = CreateDestination(session, DestinationType.Queue))
using(IMessageConsumer consumer = session.CreateConsumer(destination))
{
IDestination destination = CreateDestination(session, DestinationType.Queue);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
consumer.Listener += new MessageListener(OnMessage);
using(IMessageProducer producer = session.CreateProducer(destination))
{
consumer.Listener += new MessageListener(OnMessage);
using(IMessageProducer producer = session.CreateProducer(destination))
{
producer.DeliveryMode = deliveryMode;

ITextMessage request = session.CreateTextMessage("Hello, World!");
request.NMSCorrelationID = "AsyncConsumeTextMessage";
request.Properties["NMSXGroupID"] = "cheese";
request.Properties["myHeader"] = "James";

producer.Send(request);

WaitForMessageToArrive();
Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID.");
Assert.AreEqual(request.Properties["NMSXGroupID"], receivedMsg.Properties["NMSXGroupID"], "Invalid NMSXGroupID.");
Assert.AreEqual(request.Properties["myHeader"], receivedMsg.Properties["myHeader"], "Invalid myHeader.");
Assert.AreEqual(request.Text, ((ITextMessage) receivedMsg).Text, "Invalid text body.");
}
producer.DeliveryMode = deliveryMode;

ITextMessage request = session.CreateTextMessage("Hello, World!");
request.NMSCorrelationID = "AsyncConsumeTextMessage";
request.Properties["NMSXGroupID"] = "cheese";
request.Properties["myHeader"] = "James";

producer.Send(request);

WaitForMessageToArrive();
Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID.");
Assert.AreEqual(request.Properties["NMSXGroupID"], receivedMsg.Properties["NMSXGroupID"], "Invalid NMSXGroupID.");
Assert.AreEqual(request.Properties["myHeader"], receivedMsg.Properties["myHeader"], "Invalid myHeader.");
Assert.AreEqual(request.Text, ((ITextMessage) receivedMsg).Text, "Invalid text body.");
}
}
}
@@ -182,27 +174,24 @@ public override void TearDown()
{
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
using(ITemporaryQueue tempReplyDestination = session.CreateTemporaryQueue())
using(IDestination destination = CreateDestination(session, DestinationType.Queue))
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageConsumer tempConsumer = session.CreateConsumer(tempReplyDestination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
IDestination destination = CreateDestination(session, DestinationType.Queue);
ITemporaryQueue tempReplyDestination = session.CreateTemporaryQueue();

using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageConsumer tempConsumer = session.CreateConsumer(tempReplyDestination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
producer.DeliveryMode = deliveryMode;
tempConsumer.Listener += new MessageListener(OnMessage);
consumer.Listener += new MessageListener(OnQueueMessage);

IMessage request = session.CreateMessage();
request.NMSCorrelationID = "TemqQueueAsyncConsume";
request.NMSType = "Test";
request.NMSReplyTo = tempReplyDestination;
producer.Send(request);

WaitForMessageToArrive();
Assert.AreEqual("TempQueueAsyncResponse", receivedMsg.NMSCorrelationID, "Invalid correlation ID.");
}
producer.DeliveryMode = deliveryMode;
tempConsumer.Listener += new MessageListener(OnMessage);
consumer.Listener += new MessageListener(OnQueueMessage);

IMessage request = session.CreateMessage();
request.NMSCorrelationID = "TemqQueueAsyncConsume";
request.NMSType = "Test";
request.NMSReplyTo = tempReplyDestination;
producer.Send(request);

WaitForMessageToArrive();
Assert.AreEqual("TempQueueAsyncResponse", receivedMsg.NMSCorrelationID, "Invalid correlation ID.");
}
}
}
@@ -214,16 +203,14 @@ protected void OnQueueMessage(IMessage message)
{
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
using(IMessageProducer producer = session.CreateProducer(message.NMSReplyTo))
{
using(IMessageProducer producer = session.CreateProducer(message.NMSReplyTo))
{
producer.DeliveryMode = message.NMSDeliveryMode;
producer.DeliveryMode = message.NMSDeliveryMode;

ITextMessage response = session.CreateTextMessage("Asynchronous Response Message Text");
response.NMSCorrelationID = "TempQueueAsyncResponse";
response.NMSType = message.NMSType;
producer.Send(response);
}
ITextMessage response = session.CreateTextMessage("Asynchronous Response Message Text");
response.NMSCorrelationID = "TempQueueAsyncResponse";
response.NMSType = message.NMSType;
producer.Send(response);
}
}
}

0 comments on commit da1b979

Please sign in to comment.