completed messaging documentation. Minor improvements to NMS apis using delegates.

This commit is contained in:
markpollack
2008-08-07 05:16:34 +00:00
parent bc6029a8a7
commit f2410efaf6
21 changed files with 1247 additions and 429 deletions

View File

@@ -1051,6 +1051,9 @@
<copy todir="${current.package.dir}/doc/schema"
file="src/Spring/Spring.Services/Remoting/Config/spring-remoting-1.1.xsd"/>
<copy todir="${current.package.dir}/doc/schema"
file="src/Spring/Spring.Services/Remoting/Config/spring-nms-1.2.xsd"/>
<copy todir="${current.package.dir}/doc/schema"
file="build-support/install-schema.build"/>

File diff suppressed because it is too large Load Diff

View File

@@ -255,6 +255,44 @@
&lt;/parsers&gt;
&lt;/spring&gt;
&lt;/configuration&gt;</programlisting>
</section>
<section id="xsd-config-body-schemas-remoting">
<title>The <literal>nms</literal> messaging schema</title>
<para>The <literal>nms</literal> tags are for use when you want to
configure Spring's messaging support. The tags are comprehensively
covered in the chapter <xref linkend="messaging" /></para>
<programlisting>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;objects xmlns="http://www.springframework.net"
<emphasis role="bold">xmlns:r="http://www.springframework.net/nms"</emphasis>&gt;
<lineannotation> &lt;!-- <literal>&lt;object/&gt;</literal> definitions here --&gt;</lineannotation>
&lt;!-- &lt;nms/&gt; remoting definitions here --&gt;
&lt;/objects&gt;</programlisting>
<para>You will also need to configure the remoting namespace parser in
the main .NET application configuration file as shown below</para>
<programlisting>&lt;configuration&gt;
&lt;configSections&gt;
&lt;sectionGroup name="spring"&gt;
&lt;!-- other Spring config sections handler like context, typeAliases, etc not shown for brevity --&gt;
&lt;section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core"/&gt;
&lt;/sectionGroup&gt;
&lt;/configSections&gt;
&lt;spring&gt;
&lt;parsers&gt;
&lt;parser type="Spring.Messaging.Nms.Config.NmsNamespaceParser, Spring.Messaging.Nms" /&gt;
&lt;/parsers&gt;
&lt;/spring&gt;
&lt;/configuration&gt;</programlisting>
</section>

View File

@@ -40,11 +40,11 @@
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="connection-factory" type="xsd:string" default="connectionFactory">
<xsd:attribute name="connection-factory" type="xsd:string" default="ConnectionFactory">
<xsd:annotation>
<xsd:documentation><![CDATA[
A reference to the NMS ConnectionFactory bean.
Default is "connectionFactory".
Default is "ConnectionFactory".
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>

View File

@@ -75,7 +75,7 @@ namespace Spring.Messaging.Nms.Connections
/// </summary>
/// <remarks>
/// The ConnectionFactory has to be set before using the instance.
/// This constructor can be used to prepare a MessageTemplate via a ApplicationContext,
/// This constructor can be used to prepare a NmsTemplate via a ApplicationContext,
/// typically setting the ConnectionFactory via ConnectionFactory property.
/// <para>
/// Turns off transaction synchronization by default, as this manager might

View File

@@ -22,7 +22,7 @@ using Apache.NMS;
namespace Spring.Messaging.Nms.Core
{
/// <summary> To be used with MessageTemplate's send method that
/// <summary> To be used with NmsTemplate's send method that
/// convert an object to a message.
/// </summary>
/// <remarks>

View File

@@ -25,10 +25,10 @@ namespace Spring.Messaging.Nms.Core
/// <summary>Specifies a basic set of NMS operations.
/// </summary>
/// <remarks>
/// <p>Implemented by MessageTemplate. Not often used but a useful option
/// <p>Implemented by NmsTemplate. Not often used but a useful option
/// to enhance testability, as it can easily be mocked or stubbed.</p>
///
/// <p>Provides <code>MessageTemplate's</code> <code>send(..)</code> and
/// <p>Provides <code>NmsTemplate's</code> <code>send(..)</code> and
/// <code>receive(..)</code> methods that mirror various NMS API methods.
/// See the NMS specification and NMS API docs for details on those methods.
/// </p>
@@ -42,10 +42,6 @@ namespace Spring.Messaging.Nms.Core
/// a NMS Session.
/// </summary>
/// <remarks>
/// <para>Note that the value of PubSubDomain affects the behavior of this method.
/// If PubSubDomain equals true, then a Session is passed to the callback.
/// If false, then a ISession is passed to the callback.</para>b
/// </remarks>
/// <param name="action">callback object that exposes the session
/// </param>
/// <returns> the result object from working with the session
@@ -57,10 +53,6 @@ namespace Spring.Messaging.Nms.Core
/// a NMS Session.
/// </summary>
/// <remarks>
/// <para>Note that the value of PubSubDomain affects the behavior of this method.
/// If PubSubDomain equals true, then a Session is passed to the callback.
/// If false, then a ISession is passed to the callback.</para>b
/// </remarks>
/// <param name="del">delegate that exposes the session</param>
/// <returns> the result object from working with the session
/// </returns>
@@ -71,13 +63,23 @@ namespace Spring.Messaging.Nms.Core
/// the NMS session and MessageProducer in order to do more complex
/// send operations.
/// </summary>
/// <param name="action">callback object that exposes the session/producer pair
/// <param name="del">delegate that exposes the session/producer pair
/// </param>
/// <returns> the result object from working with the session
/// </returns>
/// <throws>NMSException if there is any problem </throws>
object Execute(IProducerCallback action);
object Execute(ProducerDelegate del);
/// <summary> Send a message to a NMS destination. The callback gives access to
/// the NMS session and MessageProducer in order to do more complex
/// send operations.
/// </summary>
/// <param name="action">callback object that exposes the session/producer pair
/// </param>
/// <returns> the result object from working with the session
/// </returns>
/// <throws>NMSException if there is any problem </throws>
object Execute(IProducerCallback action);
//-------------------------------------------------------------------------
// Convenience methods for sending messages
@@ -122,7 +124,7 @@ namespace Spring.Messaging.Nms.Core
/// <param name="messageCreatorDelegate">delegate callback to create a message
/// </param>
/// <throws>NMSException if there is any problem</throws>
void SendWithDelegate(IMessageCreatorDelegate messageCreatorDelegate);
void SendWithDelegate(MessageCreatorDelegate messageCreatorDelegate);
/// <summary> Send a message to the specified destination.
/// The IMessageCreator callback creates the message given a Session.
@@ -132,7 +134,7 @@ namespace Spring.Messaging.Nms.Core
/// <param name="messageCreatorDelegate">delegate callback to create a message
/// </param>
/// <throws>NMSException if there is any problem</throws>
void SendWithDelegate(IDestination destination, IMessageCreatorDelegate messageCreatorDelegate);
void SendWithDelegate(IDestination destination, MessageCreatorDelegate messageCreatorDelegate);
/// <summary> Send a message to the specified destination.
/// The IMessageCreator callback creates the message given a Session.
@@ -143,7 +145,7 @@ namespace Spring.Messaging.Nms.Core
/// <param name="messageCreatorDelegate">delegate callback to create a message
/// </param>
/// <throws>NMSException if there is any problem</throws>
void SendWithDelegate(string destinationName, IMessageCreatorDelegate messageCreatorDelegate);
void SendWithDelegate(string destinationName, MessageCreatorDelegate messageCreatorDelegate);
//-------------------------------------------------------------------------
// Convenience methods for sending auto-converted messages
@@ -217,7 +219,40 @@ namespace Spring.Messaging.Nms.Core
/// </param>
/// <throws>NMSException if there is any problem</throws>
void ConvertAndSend(string destinationName, object message, IMessagePostProcessor postProcessor);
/// <summary>
/// Send the given object to the default destination, converting the object
/// to a NMS message with a configured IMessageConverter. The IMessagePostProcessor
/// callback allows for modification of the message after conversion.
/// <p>This will only work with a default destination specified!</p>
/// </summary>
/// <param name="message">the object to convert to a message</param>
/// <param name="postProcessor">the callback to modify the message</param>
/// <throws>NMSException if there is any problem</throws>
void ConvertAndSendWithDelegate(object message, MessagePostProcessorDelegate postProcessor);
/// <summary>
/// Send the given object to the specified destination, converting the object
/// to a NMS message with a configured IMessageConverter. The IMessagePostProcessor
/// callback allows for modification of the message after conversion.
/// </summary>
/// <param name="destination">the destination to send this message to</param>
/// <param name="message">the object to convert to a message</param>
/// <param name="postProcessor">the callback to modify the message</param>
/// <throws>NMSException if there is any problem</throws>
void ConvertAndSendWithDelegate(IDestination destination, object message, MessagePostProcessorDelegate postProcessor);
/// <summary>
/// Send the given object to the specified destination, converting the object
/// to a NMS message with a configured IMessageConverter. The IMessagePostProcessor
/// callback allows for modification of the message after conversion.
/// </summary>
/// <param name="destinationName">the name of the destination to send this message to
/// (to be resolved to an actual destination by a DestinationResolver)</param>
/// <param name="message">the object to convert to a message.</param>
/// <param name="postProcessor">the callback to modify the message</param>
/// <throws>NMSException if there is any problem</throws>
void ConvertAndSendWithDelegate(string destinationName, object message, MessagePostProcessorDelegate postProcessor);
//-------------------------------------------------------------------------
// Convenience methods for receiving messages

View File

@@ -26,7 +26,7 @@ namespace Spring.Messaging.Nms.Core
/// Session
/// </summary>
/// <remarks>
/// <para>To be used with the MessageTemplate.Execute(ISessionCallback)}
/// <para>To be used with the NmsTemplate.Execute(ISessionCallback)}
/// method. See <see cref="SessionDelegate"/> for the equivalent callback
/// that can be used as a (anonymous) delegate.</para>
/// </remarks>

View File

@@ -31,5 +31,5 @@ namespace Spring.Messaging.Nms.Core
/// <returns> the <code>Message</code> to be sent
/// </returns>
/// <throws>NMSException if thrown by NMS API methods </throws>
public delegate IMessage IMessageCreatorDelegate(ISession session);
public delegate IMessage MessageCreatorDelegate(ISession session);
}

View File

@@ -0,0 +1,35 @@
#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
{
/// <summary>
/// Delegate that is used with NmsTemplate's ConvertAndSend method that converts
/// an object.
/// </summary>
/// It allows for further modification of the message after it has been processed
/// by the converter. This is useful for setting of NMS Header and Properties.
/// </remarks>
/// <author>Mark Pollack</author>
public delegate IMessage MessagePostProcessorDelegate(IMessage message);
}

View File

@@ -29,9 +29,9 @@ namespace Spring.Messaging.Nms.Core
/// Convenient super class for application classes that need NMS access.
/// </summary>
/// <remarks>
/// Requires a ConnectionFactory or a MessageTemplate instance to be set.
/// It will create its own MessageTemplate if a ConnectionFactory is passed in.
/// A custom MessageTemplate instance can be created for a given ConnectionFactory
/// Requires a ConnectionFactory or a NmsTemplate instance to be set.
/// It will create its own NmsTemplate if a ConnectionFactory is passed in.
/// A custom NmsTemplate instance can be created for a given ConnectionFactory
/// through overriding the <code>createNmsTemplate</code> method.
///
/// </remarks>
@@ -59,7 +59,7 @@ namespace Spring.Messaging.Nms.Core
/// <summary>
/// Gets or sets he NMS connection factory to be used by the gateway.
/// Will automatically create a MessageTemplate for the given ConnectionFactory.
/// Will automatically create a NmsTemplate for the given ConnectionFactory.
/// </summary>
/// <value>The connection factory.</value>
public IConnectionFactory ConnectionFactory
@@ -75,10 +75,10 @@ namespace Spring.Messaging.Nms.Core
}
/// <summary>
/// Creates a MessageTemplate for the given ConnectionFactory.
/// Creates a NmsTemplate for the given ConnectionFactory.
/// </summary>
/// <remarks>Only invoked if populating the gateway with a ConnectionFactory reference.
/// Can be overridden in subclasses to provide a different MessageTemplate instance
/// Can be overridden in subclasses to provide a different NmsTemplate instance
/// </remarks>
///
/// <param name="connectionFactory">The connection factory.</param>

View File

@@ -63,7 +63,7 @@ namespace Spring.Messaging.Nms.Core
/// </summary>
public static readonly long DEFAULT_RECEIVE_TIMEOUT = -1;
private MessageTemplateResourceFactory transactionalResourceFactory;
private NmsTemplateResourceFactory transactionalResourceFactory;
private object defaultDestination;
@@ -90,20 +90,20 @@ namespace Spring.Messaging.Nms.Core
#region Constructor (s)
/// <summary> Create a new MessageTemplate.</summary>
/// <summary> Create a new NmsTemplate.</summary>
/// <remarks>
/// <para>Note: The ConnectionFactory has to be set before using the instance.
/// This constructor can be used to prepare a MessageTemplate via an ObjectFactory,
/// This constructor can be used to prepare a NmsTemplate via an ObjectFactory,
/// typically setting the ConnectionFactory.</para>
/// </remarks>
public NmsTemplate()
{
transactionalResourceFactory = new MessageTemplateResourceFactory(this);
transactionalResourceFactory = new NmsTemplateResourceFactory(this);
InitDefaultStrategies();
}
/// <summary> Create a new MessageTemplate, given a ConnectionFactory.</summary>
/// <summary> Create a new NmsTemplate, given a ConnectionFactory.</summary>
/// <param name="connectionFactory">the ConnectionFactory to obtain IConnections from
/// </param>
public NmsTemplate(IConnectionFactory connectionFactory)
@@ -130,7 +130,7 @@ namespace Spring.Messaging.Nms.Core
if (defaultDestination == null)
{
throw new SystemException(
"No defaultDestination or defaultDestinationName specified. Check configuration of MessageTemplate.");
"No defaultDestination or defaultDestinationName specified. Check configuration of NmsTemplate.");
}
}
@@ -139,7 +139,7 @@ namespace Spring.Messaging.Nms.Core
{
if (MessageConverter == null)
{
throw new SystemException("No messageConverter registered. Check configuration of MessageTemplate.");
throw new SystemException("No messageConverter registered. Check configuration of NmsTemplate.");
}
}
@@ -493,7 +493,7 @@ namespace Spring.Messaging.Nms.Core
/// <param name="session">The session to operate on.</param>
/// <param name="destination">The destination to send to.</param>
/// <param name="messageCreatorDelegate">The message creator delegate callback to create a Message.</param>
protected internal virtual void DoSend(ISession session, IDestination destination, IMessageCreatorDelegate messageCreatorDelegate)
protected internal virtual void DoSend(ISession session, IDestination destination, MessageCreatorDelegate messageCreatorDelegate)
{
AssertUtils.ArgumentNotNull(messageCreatorDelegate, "IMessageCreatorDelegate must not be null");
DoSend(session, destination, null, messageCreatorDelegate);
@@ -522,7 +522,7 @@ namespace Spring.Messaging.Nms.Core
/// </param>
/// <throws>NMSException if thrown by NMS API methods </throws>
protected internal virtual void DoSend(ISession session, IDestination destination, IMessageCreator messageCreator,
IMessageCreatorDelegate messageCreatorDelegate)
MessageCreatorDelegate messageCreatorDelegate)
{
@@ -630,13 +630,27 @@ namespace Spring.Messaging.Nms.Core
return Execute(new ProducerCreatorCallback(this, action));
}
/// <summary> Send a message to a NMS destination. The callback gives access to
/// the NMS session and MessageProducer in order to do more complex
/// send operations.
/// </summary>
/// <param name="del">delegate that exposes the session/producer pair
/// </param>
/// <returns> the result object from working with the session
/// </returns>
/// <throws>NMSException if there is any problem </throws>
public object Execute(ProducerDelegate del)
{
return Execute(new ProducerCreatorCallback(this, del));
}
/// <summary> Send a message to the default destination.
/// <p>This will only work with a default destination specified!</p>
/// </summary>
/// <param name="messageCreatorDelegate">delegate callback to create a message
/// </param>
/// <throws>NMSException if there is any problem</throws>
public void SendWithDelegate(IMessageCreatorDelegate messageCreatorDelegate)
public void SendWithDelegate(MessageCreatorDelegate messageCreatorDelegate)
{
CheckDefaultDestination();
if (DefaultDestination != null)
@@ -657,7 +671,7 @@ namespace Spring.Messaging.Nms.Core
/// <param name="messageCreatorDelegate">delegate callback to create a message
/// </param>
/// <throws>NMSException if there is any problem</throws>
public void SendWithDelegate(IDestination destination, IMessageCreatorDelegate messageCreatorDelegate)
public void SendWithDelegate(IDestination destination, MessageCreatorDelegate messageCreatorDelegate)
{
Execute(new SendDestinationCallback(this, destination, messageCreatorDelegate), false);
}
@@ -671,7 +685,7 @@ namespace Spring.Messaging.Nms.Core
/// <param name="messageCreatorDelegate">delegate callback to create a message
/// </param>
/// <throws>NMSException if there is any problem</throws>
public void SendWithDelegate(string destinationName, IMessageCreatorDelegate messageCreatorDelegate)
public void SendWithDelegate(string destinationName, MessageCreatorDelegate messageCreatorDelegate)
{
Execute(new SendDestinationCallback(this, destinationName, messageCreatorDelegate), false);
}
@@ -829,6 +843,64 @@ namespace Spring.Messaging.Nms.Core
}
/// <summary>
/// Send the given object to the default destination, converting the object
/// to a NMS message with a configured IMessageConverter. The IMessagePostProcessor
/// callback allows for modification of the message after conversion.
/// <p>This will only work with a default destination specified!</p>
/// </summary>
/// <param name="message">the object to convert to a message</param>
/// <param name="postProcessor">the callback to modify the message</param>
/// <throws>NMSException if there is any problem</throws>
public void ConvertAndSendWithDelegate(object message, MessagePostProcessorDelegate postProcessor)
{
//Execute(new SendDestinationCallback(this, destination, messageCreatorDelegate), false);
CheckDefaultDestination();
if (DefaultDestination != null)
{
ConvertAndSendWithDelegate(DefaultDestination, message, postProcessor);
}
else
{
ConvertAndSendWithDelegate(DefaultDestinationName, message, postProcessor);
}
}
/// <summary>
/// Send the given object to the specified destination, converting the object
/// to a NMS message with a configured IMessageConverter. The IMessagePostProcessor
/// callback allows for modification of the message after conversion.
/// </summary>
/// <param name="destination">the destination to send this message to</param>
/// <param name="message">the object to convert to a message</param>
/// <param name="postProcessor">the callback to modify the message</param>
/// <throws>NMSException if there is any problem</throws>
public void ConvertAndSendWithDelegate(IDestination destination, object message,
MessagePostProcessorDelegate postProcessor)
{
CheckMessageConverter();
Send(destination, new ConvertAndSendMessageCreator(this, message, postProcessor));
}
/// <summary>
/// Send the given object to the specified destination, converting the object
/// to a NMS message with a configured IMessageConverter. The IMessagePostProcessor
/// callback allows for modification of the message after conversion.
/// </summary>
/// <param name="destinationName">the name of the destination to send this message to
/// (to be resolved to an actual destination by a DestinationResolver)</param>
/// <param name="message">the object to convert to a message.</param>
/// <param name="postProcessor">the callback to modify the message</param>
/// <throws>NMSException if there is any problem</throws>
public void ConvertAndSendWithDelegate(string destinationName, object message,
MessagePostProcessorDelegate postProcessor)
{
CheckMessageConverter();
Send(destinationName, new ConvertAndSendMessageCreator(this, message, postProcessor));
}
/// <summary> Receive a message synchronously from the default destination, but only
/// wait up to a specified time for delivery.
/// <p>This method should be used carefully, since it will block the thread
@@ -1123,11 +1195,11 @@ namespace Spring.Messaging.Nms.Core
/// <summary>
/// ResourceFactory implementation that delegates to this template's callback methods.
/// </summary>
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;

View File

@@ -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
{
/// <summary> Perform operations on the given Session and MessageProducer.
/// The message producer is not associated with any destination.
/// </summary>
/// <param name="session">the NMS <code>Session</code> object to use
/// </param>
/// <param name="producer">the NMS <code>MessageProducer</code> object to use
/// </param>
/// <returns> a result object from working with the <code>Session</code>, if any (can be <code>null</code>)
/// </returns>
public delegate object ProducerDelegate(ISession session, IMessageProducer producer);
}

View File

@@ -218,7 +218,7 @@ namespace Spring.Messaging.Nms.Listener
/// on some messaging providers.
/// <para>Note that Sessions managed by an external transaction manager will
/// always get exposed to <see cref="NmsTemplate"/>
/// 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.
/// </para>
/// </remarks>

View File

@@ -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;

View File

@@ -26,7 +26,7 @@ using Apache.NMS;
namespace Spring.Messaging.Nms.Support.Converter
{
/// <summary> 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
/// <code>ConvertAndSend</code> and <code>ReceiveAndConvert</code> operations.
///
/// <p>Converts a String to a NMS ITextMessage, a byte array to a NMS IBytesMessage,

View File

@@ -23,12 +23,12 @@ using Apache.NMS;
namespace Spring.Messaging.Nms.Support.Destinations
{
/// <summary> Base class for MessageTemplate} and other
/// <summary> Base class for NmsTemplate} and other
/// NMS-accessing gateway helpers, adding destination-related properties to
/// MessagingAccessor's common properties.
/// </summary>
/// <remarks>
/// <p>Not intended to be used directly. See MessageTemplate.</p>
/// <p>Not intended to be used directly. See NmsTemplate.</p>
///
/// </remarks>
/// <author>Juergen Hoeller </author>

View File

@@ -25,11 +25,11 @@ using Apache.NMS;
namespace Spring.Messaging.Nms.Support
{
/// <summary> Base class for MessageTemplate and other NMS-accessing gateway helpers</summary>
/// <summary> Base class for NmsTemplate and other NMS-accessing gateway helpers</summary>
/// <remarks>It defines common properties like the ConnectionFactory}. The subclass
/// NmsIDestinationAccessor adds further, destination-related properties.
/// <para>
/// Not intended to be used directly. See MessageTemplate.
/// Not intended to be used directly. See NmsTemplate.
/// </para>
/// </remarks>
/// <author>Juergen Hoeller</author>

View File

@@ -55,8 +55,10 @@
<Compile Include="Messaging\Nms\Core\IProducerCallback.cs" />
<Compile Include="Messaging\Nms\Core\ISessionCallback.cs" />
<Compile Include="Messaging\Nms\Core\MessageCreatorDelegate.cs" />
<Compile Include="Messaging\Nms\Core\MessagePostProcessorDelegate.cs" />
<Compile Include="Messaging\Nms\Core\NmsTemplate.cs" />
<Compile Include="Messaging\Nms\Core\NmsGatewaySupport.cs" />
<Compile Include="Messaging\Nms\Core\ProducerDelegate.cs" />
<Compile Include="Messaging\Nms\Core\SessionDelegate.cs" />
<Compile Include="Messaging\Nms\Config\MessageListenerContainerObjectDefinitionParser.cs" />
<Compile Include="Messaging\Nms\Config\NmsNamespaceParser.cs" />

View File

@@ -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
{

View File

@@ -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