Receive a message synchronously from the default destination, but only
/// wait up to a specified time for delivery.
/// This method should be used carefully, since it will block the thread
@@ -1123,11 +1195,11 @@ namespace Spring.Messaging.Nms.Core
///
/// ResourceFactory implementation that delegates to this template's callback methods.
///
- private class MessageTemplateResourceFactory : ConnectionFactoryUtils.ResourceFactory
+ private class NmsTemplateResourceFactory : ConnectionFactoryUtils.ResourceFactory
{
private NmsTemplate enclosingTemplateInstance;
- public MessageTemplateResourceFactory(NmsTemplate enclosingInstance)
+ public NmsTemplateResourceFactory(NmsTemplate enclosingInstance)
{
InitBlock(enclosingInstance);
}
@@ -1172,6 +1244,7 @@ namespace Spring.Messaging.Nms.Core
{
private NmsTemplate jmsTemplate;
private IProducerCallback producerCallback;
+ private ProducerDelegate producerDelegate;
public ProducerCreatorCallback(NmsTemplate jmsTemplate, IProducerCallback producerCallback)
{
@@ -1179,12 +1252,25 @@ namespace Spring.Messaging.Nms.Core
this.producerCallback = producerCallback;
}
+ public ProducerCreatorCallback(NmsTemplate jmsTemplate, ProducerDelegate producerDelegate)
+ {
+ this.jmsTemplate = jmsTemplate;
+ this.producerDelegate = producerDelegate;
+ }
+
public object DoInNms(ISession session)
{
IMessageProducer producer = jmsTemplate.CreateProducer(session, null);
try
{
- return producerCallback.DoInNms(session, producer);
+ if (producerCallback != null)
+ {
+ return producerCallback.DoInNms(session, producer);
+ }
+ else
+ {
+ return producerDelegate(session, producer);
+ }
}
finally
{
@@ -1234,6 +1320,7 @@ namespace Spring.Messaging.Nms.Core
private NmsTemplate jmsTemplate;
private object objectToConvert;
private IMessagePostProcessor messagePostProcessor;
+ private MessagePostProcessorDelegate messagePostProcessorDelegate;
public ConvertAndSendMessageCreator(NmsTemplate jmsTemplate, object message, IMessagePostProcessor messagePostProcessor)
{
@@ -1242,11 +1329,25 @@ namespace Spring.Messaging.Nms.Core
this.messagePostProcessor = messagePostProcessor;
}
+ public ConvertAndSendMessageCreator(NmsTemplate jmsTemplate, object message, MessagePostProcessorDelegate messagePostProcessorDelegate)
+ {
+ this.jmsTemplate = jmsTemplate;
+ objectToConvert = message;
+ this.messagePostProcessorDelegate = messagePostProcessorDelegate;
+ }
+
public IMessage CreateMessage(ISession session)
{
IMessage msg = jmsTemplate.MessageConverter.ToMessage(objectToConvert, session);
- return messagePostProcessor.PostProcessMessage(msg);
+ if (messagePostProcessor != null)
+ {
+ return messagePostProcessor.PostProcessMessage(msg);
+ } else
+ {
+ return messagePostProcessorDelegate(msg);
+ }
}
+
}
private class ReceiveSelectedCallback : ISessionCallback
@@ -1336,7 +1437,7 @@ namespace Spring.Messaging.Nms.Core
private IDestination destination;
private NmsTemplate jmsTemplate;
private IMessageCreator messageCreator;
- private IMessageCreatorDelegate messageCreatorDelegate;
+ private MessageCreatorDelegate messageCreatorDelegate;
public SendDestinationCallback(NmsTemplate jmsTemplate, string destinationName, IMessageCreator messageCreator)
{
@@ -1352,14 +1453,14 @@ namespace Spring.Messaging.Nms.Core
this.messageCreator = messageCreator;
}
- public SendDestinationCallback(NmsTemplate jmsTemplate, string destinationName, IMessageCreatorDelegate messageCreatorDelegate)
+ public SendDestinationCallback(NmsTemplate jmsTemplate, string destinationName, MessageCreatorDelegate messageCreatorDelegate)
{
this.jmsTemplate = jmsTemplate;
this.destinationName = destinationName;
this.messageCreatorDelegate = messageCreatorDelegate;
}
- public SendDestinationCallback(NmsTemplate jmsTemplate, IDestination destination, IMessageCreatorDelegate messageCreatorDelegate)
+ public SendDestinationCallback(NmsTemplate jmsTemplate, IDestination destination, MessageCreatorDelegate messageCreatorDelegate)
{
this.jmsTemplate = jmsTemplate;
this.destination = destination;
diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Core/ProducerDelegate.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Core/ProducerDelegate.cs
new file mode 100644
index 00000000..b71bbe35
--- /dev/null
+++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Core/ProducerDelegate.cs
@@ -0,0 +1,38 @@
+
+
+#region License
+
+/*
+ * Copyright 2002-2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#endregion
+
+using Apache.NMS;
+
+namespace Spring.Messaging.Nms.Core
+{
+ /// Perform operations on the given Session and MessageProducer.
+ /// The message producer is not associated with any destination.
+ ///
+ /// the NMS Session object to use
+ ///
+ /// the NMS MessageProducer object to use
+ ///
+ /// a result object from working with the Session, if any (can be null)
+ ///
+ public delegate object ProducerDelegate(ISession session, IMessageProducer producer);
+
+}
\ No newline at end of file
diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Listener/AbstractMessageListenerContainer.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Listener/AbstractMessageListenerContainer.cs
index 2233deab..065d433c 100644
--- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Listener/AbstractMessageListenerContainer.cs
+++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Listener/AbstractMessageListenerContainer.cs
@@ -218,7 +218,7 @@ namespace Spring.Messaging.Nms.Listener
/// on some messaging providers.
/// Note that Sessions managed by an external transaction manager will
/// always get exposed to
- /// calls. So in terms of MessageTemplate exposure, this setting only affects
+ /// calls. So in terms of NmsTemplate exposure, this setting only affects
/// locally transacted Sessions.
///
///
diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Listener/SimpleMessageListenerContainer.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Listener/SimpleMessageListenerContainer.cs
index 890297d8..23629da0 100644
--- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Listener/SimpleMessageListenerContainer.cs
+++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Listener/SimpleMessageListenerContainer.cs
@@ -190,7 +190,6 @@ namespace Spring.Messaging.Nms.Listener
{
if (this.consumers == null)
{
- logger.Debug("InitializingConsumers **********");
this.sessions = new HashedSet();
this.consumers = new HashedSet();
IConnection con = SharedConnection;
diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/Converter/SimpleMessageConverter.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/Converter/SimpleMessageConverter.cs
index 658b5923..c2bfa10a 100644
--- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/Converter/SimpleMessageConverter.cs
+++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/Converter/SimpleMessageConverter.cs
@@ -26,7 +26,7 @@ using Apache.NMS;
namespace Spring.Messaging.Nms.Support.Converter
{
/// A simple message converter that can handle ITextMessages, IBytesMessages,
- /// IMapMessages, and IObjectMessages. Used as default by MessageTemplate, for
+ /// IMapMessages, and IObjectMessages. Used as default by NmsTemplate, for
/// ConvertAndSend and ReceiveAndConvert operations.
///
/// Converts a String to a NMS ITextMessage, a byte array to a NMS IBytesMessage,
diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/Destinations/NmsDestinationAccessor.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/Destinations/NmsDestinationAccessor.cs
index ff627255..95f284fc 100644
--- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/Destinations/NmsDestinationAccessor.cs
+++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/Destinations/NmsDestinationAccessor.cs
@@ -23,12 +23,12 @@ using Apache.NMS;
namespace Spring.Messaging.Nms.Support.Destinations
{
- /// Base class for MessageTemplate} and other
+ /// Base class for NmsTemplate} and other
/// NMS-accessing gateway helpers, adding destination-related properties to
/// MessagingAccessor's common properties.
///
///
- /// Not intended to be used directly. See MessageTemplate.
+ /// Not intended to be used directly. See NmsTemplate.
///
///
/// Juergen Hoeller
diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/NmsAccessor.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/NmsAccessor.cs
index 7e5c4b4e..4d088d95 100644
--- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/NmsAccessor.cs
+++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/NmsAccessor.cs
@@ -25,11 +25,11 @@ using Apache.NMS;
namespace Spring.Messaging.Nms.Support
{
- /// Base class for MessageTemplate and other NMS-accessing gateway helpers
+ /// Base class for NmsTemplate and other NMS-accessing gateway helpers
/// It defines common properties like the ConnectionFactory}. The subclass
/// NmsIDestinationAccessor adds further, destination-related properties.
///
- /// Not intended to be used directly. See MessageTemplate.
+ /// Not intended to be used directly. See NmsTemplate.
///
///
/// Juergen Hoeller
diff --git a/src/Spring/Spring.Messaging.Nms/Spring.Messaging.Nms.2005.csproj b/src/Spring/Spring.Messaging.Nms/Spring.Messaging.Nms.2005.csproj
index 20e4ae35..6898cd1e 100644
--- a/src/Spring/Spring.Messaging.Nms/Spring.Messaging.Nms.2005.csproj
+++ b/src/Spring/Spring.Messaging.Nms/Spring.Messaging.Nms.2005.csproj
@@ -55,8 +55,10 @@
+
+
diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Core/MessageTemplateTests.cs b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Core/MessageTemplateTests.cs
index cffd2a90..f453a4f0 100644
--- a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Core/MessageTemplateTests.cs
+++ b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Core/MessageTemplateTests.cs
@@ -20,6 +20,7 @@
#region Imports
+using System;
using System.Collections;
using Apache.NMS;
using NUnit.Framework;
@@ -62,6 +63,7 @@ namespace Spring.Messaging.Nms.Core
return template;
}
+
protected virtual bool UseTransactedSession
{
get { return false; }
@@ -163,25 +165,25 @@ namespace Spring.Messaging.Nms.Core
});
Assert.AreSame(mockSession, ConnectionFactoryUtils.GetTransactionalSession(scf, null, false));
- Assert.AreSame(mockSession, ConnectionFactoryUtils.GetTransactionalSession(scf, scf.CreateConnection(), false));
+ Assert.AreSame(mockSession,
+ ConnectionFactoryUtils.GetTransactionalSession(scf, scf.CreateConnection(), false));
//In Java this test was doing 'double-duty' and testing TransactionAwareConnectionFactoryProxy, which has
//not been implemented in .NET
template.Execute(delegate(ISession session)
- {
- bool b = session.Transacted;
- return null;
- });
+ {
+ bool b = session.Transacted;
+ return null;
+ });
IList synchs = TransactionSynchronizationManager.Synchronizations;
Assert.AreEqual(1, synchs.Count);
- ITransactionSynchronization synch = (ITransactionSynchronization)synchs[0];
+ ITransactionSynchronization synch = (ITransactionSynchronization) synchs[0];
synch.BeforeCommit(false);
synch.BeforeCompletion();
synch.AfterCommit();
synch.AfterCompletion(TransactionSynchronizationStatus.Unknown);
-
}
finally
{
diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Integration/SimpleMessageListener.cs b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Integration/SimpleMessageListener.cs
index f0b4cbc0..3e17f923 100644
--- a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Integration/SimpleMessageListener.cs
+++ b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Integration/SimpleMessageListener.cs
@@ -34,6 +34,14 @@ namespace Spring.Messaging.Nms.Integration
lastReceivedMessage = message;
messageCount++;
LOG.Debug("Message listener count = " + messageCount);
+ ITextMessage textMessage = message as ITextMessage;
+ if (textMessage != null)
+ {
+ LOG.Info("Message Text = " + textMessage.Text);
+ } else
+ {
+ LOG.Warn("Can not process message of type " message.GetType());
+ }
}
#endregion