From 423ec64916322eef5d4e16ba7f7946f46b0e3cec Mon Sep 17 00:00:00 2001 From: markpollack Date: Wed, 22 Sep 2010 04:00:24 +0000 Subject: [PATCH] SPRNET-1365 - Update to ActiveMQ NMS 1.4 SPRNET-1369 - NmsTemplate was not attempting to start the connection when calling RecieveAndConvert --- .../Nms/Connections/CachedMessageConsumer .cs | 10 +++++ .../Nms/Connections/CachedMessageProducer.cs | 13 ++++++ .../Nms/Connections/CachedSession.cs | 23 +++++++++++ .../Connections/SingleConnectionFactory.cs | 40 +++++++++++++++++++ .../Messaging/Nms/Core/NmsTemplate.cs | 9 ++--- .../Messaging/Nms/Core/NmsTemplateTests.cs | 3 ++ .../Nms/Connections/TestConnection.cs | 12 ++++++ .../Nms/Connections/TestConnectionFactory.cs | 12 ++++++ .../Nms/Connections/TestMessageConsumer.cs | 6 +++ .../Nms/Connections/TestMessageProducer.cs | 6 +++ .../Messaging/Nms/Connections/TestSession.cs | 12 ++++++ .../SimpleMessageListenerContainerTests.cs | 6 +++ 12 files changed, 147 insertions(+), 5 deletions(-) diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageConsumer .cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageConsumer .cs index 4ba9ad88..8c10c0ca 100644 --- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageConsumer .cs +++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageConsumer .cs @@ -103,6 +103,16 @@ namespace Spring.Messaging.Nms.Connections // It's a cached MessageConsumer... } + /// + /// A Delegate that is called each time a Message is dispatched to allow the client to do + /// any necessary transformations on the received message before it is delivered. + /// + /// + public ConsumerTransformerDelegate ConsumerTransformer + { + get { return target.ConsumerTransformer; } + set { target.ConsumerTransformer = value; } + } /// /// Dispose of wrapped MessageConsumer diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageProducer.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageProducer.cs index 8089eaf8..3767414c 100644 --- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageProducer.cs +++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageProducer.cs @@ -187,6 +187,19 @@ namespace Spring.Messaging.Nms.Connections { return target.CreateStreamMessage(); } + + /// + /// A delegate that is called each time a Message is sent from this Producer which allows + /// the application to perform any needed transformations on the Message before it is sent. + /// The Session instance sets the delegate on each Producer it creates. + /// + /// + public ProducerTransformerDelegate ProducerTransformer + { + get { return target.ProducerTransformer; } + set { target.ProducerTransformer = value; } + } + #endregion /// diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedSession.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedSession.cs index 22ae9bb2..d6dacb9a 100644 --- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedSession.cs +++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedSession.cs @@ -534,6 +534,29 @@ namespace Spring.Messaging.Nms.Connections target.Rollback(); } + /// + /// A Delegate that is called each time a Message is dispatched to allow the client to do + /// any necessary transformations on the received message before it is delivered. + /// The Session instance sets the delegate on each Consumer it creates. + /// + /// + public ConsumerTransformerDelegate ConsumerTransformer + { + get { return target.ConsumerTransformer; } + set { target.ConsumerTransformer = value; } + } + + /// + /// A delegate that is called each time a Message is sent from this Producer which allows + /// the application to perform any needed transformations on the Message before it is sent. + /// The Session instance sets the delegate on each Producer it creates. + /// + /// + public ProducerTransformerDelegate ProducerTransformer + { + get { return target.ProducerTransformer; } + set { target.ProducerTransformer = value; } + } /// /// Gets or sets the request timeout. /// diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/SingleConnectionFactory.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/SingleConnectionFactory.cs index b79d54c4..ed53ba2b 100644 --- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/SingleConnectionFactory.cs +++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/SingleConnectionFactory.cs @@ -218,6 +218,34 @@ namespace Spring.Messaging.Nms.Connections set { targetConnectionFactory.RedeliveryPolicy = value; } } + /// + /// A Delegate that is called each time a Message is dispatched to allow the client to do + /// any necessary transformations on the received message before it is delivered. The + /// ConnectionFactory sets the provided delegate instance on each Connection instance that + /// is created from this factory, each connection in turn passes the delegate along to each + /// Session it creates which then passes that along to the Consumers it creates. + /// + /// + public ConsumerTransformerDelegate ConsumerTransformer + { + get { return targetConnectionFactory.ConsumerTransformer; } + set { targetConnectionFactory.ConsumerTransformer = value; } + } + + /// + /// A delegate that is called each time a Message is sent from this Producer which allows + /// the application to perform any needed transformations on the Message before it is sent. + /// The ConnectionFactory sets the provided delegate instance on each Connection instance that + /// is created from this factory, each connection in turn passes the delegate along to each + /// Session it creates which then passes that along to the Producers it creates. + /// + /// + public ProducerTransformerDelegate ProducerTransformer + { + get { return targetConnectionFactory.ProducerTransformer; } + set { targetConnectionFactory.ProducerTransformer = value; } + } + /// /// Gets the connection monitor. /// @@ -478,6 +506,18 @@ namespace Spring.Messaging.Nms.Connections // don't pass the call to the target. } + public ConsumerTransformerDelegate ConsumerTransformer + { + get { return target.ConsumerTransformer; } + set { target.ConsumerTransformer = value; } + } + + public ProducerTransformerDelegate ProducerTransformer + { + get { return target.ProducerTransformer; } + set { target.ProducerTransformer = value; } + } + public TimeSpan RequestTimeout { get { return target.RequestTimeout; } diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Core/NmsTemplate.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Core/NmsTemplate.cs index 41444368..deda07da 100644 --- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Core/NmsTemplate.cs +++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Core/NmsTemplate.cs @@ -958,8 +958,8 @@ namespace Spring.Messaging.Nms.Core /// /// NMSException if there is any problem public IMessage Receive(IDestination destination) - { - return Execute(new ReceiveCallback(this, destination)) as IMessage; + { + return ReceiveSelected(destination, null); } @@ -976,7 +976,7 @@ namespace Spring.Messaging.Nms.Core /// NMSException if there is any problem public IMessage Receive(string destinationName) { - return Execute(new ReceiveCallback(this, destinationName)) as IMessage; + return ReceiveSelected(destinationName, null); } /// Receive a message synchronously from the default destination, but only @@ -1038,8 +1038,7 @@ namespace Spring.Messaging.Nms.Core /// NMSException if there is any problem public IMessage ReceiveSelected(string destinationName, string messageSelector) { - return Execute(new ReceiveSelectedCallback(this, destinationName, messageSelector), true) as IMessage; - + return Execute(new ReceiveSelectedCallback(this, destinationName, messageSelector), true) as IMessage; } /// diff --git a/test/Spring/Spring.Messaging.Nms.Integration.Tests/Messaging/Nms/Core/NmsTemplateTests.cs b/test/Spring/Spring.Messaging.Nms.Integration.Tests/Messaging/Nms/Core/NmsTemplateTests.cs index 6895ea55..8d48ac3e 100644 --- a/test/Spring/Spring.Messaging.Nms.Integration.Tests/Messaging/Nms/Core/NmsTemplateTests.cs +++ b/test/Spring/Spring.Messaging.Nms.Integration.Tests/Messaging/Nms/Core/NmsTemplateTests.cs @@ -19,6 +19,7 @@ #endregion using System; +using System.Threading; using Apache.NMS; using Apache.NMS.ActiveMQ; using NUnit.Framework; @@ -44,6 +45,7 @@ namespace Spring.Messaging.Nms.Core } [Test] + [ExpectedException(typeof(Apache.NMS.NMSConnectionException))] public void ConnectionThrowException() { ConnectionFactory cf = new ConnectionFactory(); @@ -62,6 +64,7 @@ namespace Spring.Messaging.Nms.Core //Use with destination set at runtime nmsTemplate.ConvertAndSend("APP.TESTING", msgText); + AssertRecievedHelloWorldMessage(msgText, nmsTemplate.ReceiveAndConvert("APP.TESTING")); //Now using default destination set via property diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestConnection.cs b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestConnection.cs index e7fa24bb..1ebc8773 100644 --- a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestConnection.cs +++ b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestConnection.cs @@ -50,6 +50,18 @@ namespace Spring.Messaging.Nms.Connections closeCount++; } + public ConsumerTransformerDelegate ConsumerTransformer + { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + + public ProducerTransformerDelegate ProducerTransformer + { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + public TimeSpan RequestTimeout { get { throw new NotImplementedException(); } diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestConnectionFactory.cs b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestConnectionFactory.cs index f474f87e..bf2ebda3 100644 --- a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestConnectionFactory.cs +++ b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestConnectionFactory.cs @@ -31,6 +31,18 @@ namespace Spring.Messaging.Nms.Connections set { throw new NotImplementedException(); } } + public ConsumerTransformerDelegate ConsumerTransformer + { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + + public ProducerTransformerDelegate ProducerTransformer + { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + #endregion } } \ No newline at end of file diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestMessageConsumer.cs b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestMessageConsumer.cs index 54c8bc6f..5e6894d7 100644 --- a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestMessageConsumer.cs +++ b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestMessageConsumer.cs @@ -53,6 +53,12 @@ namespace Spring.Messaging.Nms.Connections throw new NotImplementedException(); } + public ConsumerTransformerDelegate ConsumerTransformer + { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + public void Dispose() { throw new NotImplementedException(); diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestMessageProducer.cs b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestMessageProducer.cs index 5b5505c4..97849f54 100644 --- a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestMessageProducer.cs +++ b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestMessageProducer.cs @@ -95,6 +95,12 @@ namespace Spring.Messaging.Nms.Connections throw new NotImplementedException(); } + public ProducerTransformerDelegate ProducerTransformer + { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + public MsgDeliveryMode DeliveryMode { get { return msgDeliveryMode; } diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestSession.cs b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestSession.cs index 3b043903..6fa6d797 100644 --- a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestSession.cs +++ b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/TestSession.cs @@ -211,6 +211,18 @@ namespace Spring.Messaging.Nms.Connections } + public ConsumerTransformerDelegate ConsumerTransformer + { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + + public ProducerTransformerDelegate ProducerTransformer + { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + public TimeSpan RequestTimeout { get { throw new NotImplementedException(); } diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Core/SimpleMessageListenerContainerTests.cs b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Core/SimpleMessageListenerContainerTests.cs index 5e414e11..4f2afb0d 100644 --- a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Core/SimpleMessageListenerContainerTests.cs +++ b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Core/SimpleMessageListenerContainerTests.cs @@ -182,6 +182,12 @@ namespace Spring.Messaging.Nms.Core throw new NotImplementedException(); } + public ConsumerTransformerDelegate ConsumerTransformer + { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + public void Dispose() { throw new NotImplementedException();