NMS Development
This commit is contained in:
@@ -42,7 +42,12 @@ namespace Spring
|
||||
{
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public object GetSingleton(string objectName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_destroyCalls.Inc();
|
||||
}
|
||||
@@ -79,7 +84,21 @@ namespace Spring
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IObjectDefinition GetObjectDefinition(string objectName)
|
||||
public string[] SingletonNames
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
#region ISingletonObjectRegistry Members
|
||||
|
||||
public int SingletonCount
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public IObjectDefinition GetObjectDefinition(string objectName)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using Spring.Messaging.Nms;
|
||||
using Common.Logging;
|
||||
|
||||
namespace Spring.Messaging.Nms.Integration
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class LoggingExceptionHandler : IExceptionListener
|
||||
{
|
||||
#region Logging Definition
|
||||
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof (LoggingExceptionHandler));
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IExceptionListener Members
|
||||
|
||||
public void OnException(Exception e)
|
||||
{
|
||||
LOG.Error("Exception processing message", e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
|
||||
using Spring.Messaging.Nms;
|
||||
using Apache.NMS;
|
||||
using Common.Logging;
|
||||
|
||||
namespace Spring.Messaging.Nms.Integration
|
||||
{
|
||||
public class SimpleMessageListener : IMessageListener
|
||||
{
|
||||
#region Logging Definition
|
||||
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(SimpleMessageListener));
|
||||
#endregion
|
||||
|
||||
private IMessage lastReceivedMessage;
|
||||
private int messageCount;
|
||||
|
||||
public IMessage LastReceivedMessage
|
||||
{
|
||||
get { return lastReceivedMessage; }
|
||||
}
|
||||
|
||||
|
||||
public int MessageCount
|
||||
{
|
||||
get { return messageCount; }
|
||||
}
|
||||
|
||||
#region IMessageListener Members
|
||||
|
||||
public void OnMessage(IMessage message)
|
||||
{
|
||||
lastReceivedMessage = message;
|
||||
messageCount++;
|
||||
LOG.Debug("Message listener count = " + messageCount);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2007 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using Spring.Messaging.Nms.Listener;
|
||||
using Spring.Testing.NUnit;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Messaging.Nms.Integration
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains tests for
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id:$</version>
|
||||
[TestFixture]
|
||||
public class SimpleMessageListenerContainerTests : AbstractDependencyInjectionSpringContextTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
[Explicit]
|
||||
public void SendAndAsyncReceive()
|
||||
{
|
||||
SimpleMessageListenerContainer container =
|
||||
(SimpleMessageListenerContainer) applicationContext["SimpleMessageListenerContainer"];
|
||||
SimpleMessageListener listener = applicationContext["SimpleMessageListener"] as SimpleMessageListener;
|
||||
Assert.IsNotNull(container);
|
||||
Assert.IsNotNull(listener);
|
||||
|
||||
|
||||
NmsTemplate nmsTemplate = (NmsTemplate) applicationContext["NmsTemplate"] as NmsTemplate;
|
||||
Assert.IsNotNull(nmsTemplate);
|
||||
|
||||
Assert.AreEqual(0, listener.MessageCount);
|
||||
nmsTemplate.ConvertAndSend("Hello World 1");
|
||||
|
||||
int waitInMillis = 2000;
|
||||
Thread.Sleep(waitInMillis);
|
||||
Assert.AreEqual(1,listener.MessageCount);
|
||||
|
||||
container.Stop();
|
||||
Console.WriteLine("container stopped.");
|
||||
nmsTemplate.ConvertAndSend("Hello World 2");
|
||||
Thread.Sleep(waitInMillis);
|
||||
Assert.AreEqual(1, listener.MessageCount);
|
||||
|
||||
container.Start();
|
||||
Console.WriteLine("container started.");
|
||||
Thread.Sleep(waitInMillis);
|
||||
Assert.AreEqual(2, listener.MessageCount);
|
||||
|
||||
container.Shutdown();
|
||||
|
||||
Thread.Sleep(waitInMillis);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected override string[] ConfigLocations
|
||||
{
|
||||
get { return new string[] { "assembly://Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Integration/SimpleMessageListenerContainerTests.xml" }; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net">
|
||||
|
||||
|
||||
<object name="ConnectionFactory" type="Apache.NMS.ActiveMQ.ConnectionFactory, Apache.NMS.ActiveMQ">
|
||||
<property name="BrokerUri" value="tcp://localhost:61616"/>
|
||||
</object>
|
||||
<!--
|
||||
<object name="SingleConnectionFactory" type="Spring.Messaging.Nms.Connection.SingleConnectionFactory, Spring.Messaging.Nms">
|
||||
<property name="TargetConnectionFactory" ref="ConnectionFactory"/>
|
||||
</object>
|
||||
-->
|
||||
|
||||
<object name="SimpleMessageListenerContainer" type="Spring.Messaging.Nms.Listener.SimpleMessageListenerContainer, Spring.Messaging.Nms">
|
||||
<property name="ConnectionFactory" ref="ConnectionFactory"/>
|
||||
<property name="DestinationName" value="test.queue"/>
|
||||
<property name="MessageListener" ref="SimpleMessageListener"/>
|
||||
<property name="ExceptionListener">
|
||||
<object type="Spring.Messaging.Nms.Integration.LoggingExceptionHandler, Spring.Messaging.Nms.Tests"/>
|
||||
</property>
|
||||
</object>
|
||||
|
||||
<object id="SimpleMessageListener" type="Spring.Messaging.Nms.Integration.SimpleMessageListener, Spring.Messaging.Nms.Tests"/>
|
||||
|
||||
|
||||
<object name="NmsTemplate" type="Spring.Messaging.Nms.NmsTemplate, Spring.Messaging.Nms">
|
||||
<property name="ConnectionFactory" ref="ConnectionFactory"/>
|
||||
<property name="DefaultDestinationName" value="test.queue"/>
|
||||
</object>
|
||||
</objects>
|
||||
@@ -37,6 +37,10 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\Apache.NMS.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Apache.NMS.ActiveMQ, Version=1.0.0.0, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\Apache.NMS.ActiveMQ.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Common.Logging, Version=1.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\Common.Logging.dll</HintPath>
|
||||
@@ -74,6 +78,10 @@
|
||||
<Project>{AEB1578C-9018-4D49-B440-789F38DD2F29}</Project>
|
||||
<Name>Spring.Messaging.Nms.2005</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\src\Spring\Spring.Testing.NUnit\Spring.Testing.NUnit.2005.csproj">
|
||||
<Project>{ED204A7B-832F-44C7-BFE3-504AEBE1BCC8}</Project>
|
||||
<Name>Spring.Testing.NUnit.2005</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Spring.Core.Tests\Spring.Core.Tests.2005.csproj">
|
||||
<Project>{44B16BAA-6DF8-447C-9D7F-3AD3D854D904}</Project>
|
||||
<Name>Spring.Core.Tests.2005</Name>
|
||||
@@ -87,8 +95,12 @@
|
||||
<Compile Include="Messaging\Nms\Connections\TestExceptionListener.cs" />
|
||||
<Compile Include="Messaging\Nms\Connections\TestMessageProducer.cs" />
|
||||
<Compile Include="Messaging\Nms\Connections\TestSession.cs" />
|
||||
<Compile Include="Messaging\Nms\Integration\LoggingExceptionHandler.cs" />
|
||||
<Compile Include="Messaging\Nms\Integration\SimpleMessageListener.cs" />
|
||||
<Compile Include="Messaging\Nms\Integration\SimpleMessageListenerContainerTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Messaging\Nms\Integration\SimpleMessageListenerContainerTests.xml" />
|
||||
<Content Include="Spring.Messaging.Nms.Tests.dll.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
||||
@@ -17,9 +17,20 @@ limitations under the License.
|
||||
<configuration>
|
||||
|
||||
<configSections>
|
||||
|
||||
<sectionGroup name="common">
|
||||
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
|
||||
|
||||
<common>
|
||||
<logging>
|
||||
<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
|
||||
<arg key="level" value="DEBUG" />
|
||||
<arg key="showLogName" value="true" />
|
||||
<arg key="showDataTime" value="true" />
|
||||
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
|
||||
</factoryAdapter>
|
||||
</logging>
|
||||
</common>
|
||||
|
||||
</configuration>
|
||||
|
||||
Reference in New Issue
Block a user