Skip to content
Permalink
Browse files
Adds MessageTransformation abstract class to NMS util and implements for Stomp and ActiveMQ clients.
  • Loading branch information
Timothy A. Bish committed Aug 25, 2010
1 parent 129566f commit 2e651af59e0f4af8ee4a63d0c8f3ce0ee8f597dc
Showing 6 changed files with 125 additions and 19 deletions.
@@ -176,6 +176,7 @@ public string NMSCorrelationID
public IDestination NMSDestination
{
get { return Destination; }
set { this.Destination = value as Destination; }
}

private TimeSpan timeToLive = TimeSpan.FromMilliseconds(0);
@@ -286,6 +287,24 @@ public MsgPriority NMSPriority
public bool NMSRedelivered
{
get { return (RedeliveryCounter > 0); }

set
{
if(value == true)
{
if(this.RedeliveryCounter <= 0)
{
this.RedeliveryCounter = 1;
}
}
else
{
if(this.RedeliveryCounter > 0)
{
this.RedeliveryCounter = 0;
}
}
}
}

/// <summary>
@@ -64,6 +64,7 @@ public class Connection : IConnection
private bool disposed = false;
private IdGenerator clientIdGenerator;
private CountDownLatch transportInterruptionProcessingComplete;
private MessageTransformation messageTransformation;

public Connection(Uri connectionUri, ITransport transport, IdGenerator clientIdGenerator)
{
@@ -81,6 +82,8 @@ public Connection(Uri connectionUri, ITransport transport, IdGenerator clientIdG

this.info = new ConnectionInfo();
this.info.ConnectionId = id;

this.messageTransformation = new StompMessageTransformation(this);
}

~Connection()
@@ -272,6 +275,11 @@ public PrefetchPolicy PrefetchPolicy
set { this.prefetchPolicy = value; }
}

internal MessageTransformation MessageTransformation
{
get { return this.messageTransformation; }
}

#endregion

/// <summary>
@@ -42,11 +42,14 @@ public class MessageProducer : IMessageProducer
private bool disableMessageTimestamp = false;
protected bool disposed = false;

private MessageTransformation messageTransformation;

public MessageProducer(Session session, ProducerInfo info)
{
this.session = session;
this.info = info;
this.RequestTimeout = session.RequestTimeout;
this.messageTransformation = session.Connection.MessageTransformation;
}

~MessageProducer()
@@ -165,7 +168,7 @@ public void Send(IDestination destination, IMessage message, MsgDeliveryMode del
throw new NotSupportedException("This producer can only send messages to: " + this.info.Destination.PhysicalName);
}

Message stompMessage = (Message) message;
Message stompMessage = this.messageTransformation.TransformMessage<Message>(message);

stompMessage.ProducerId = info.ProducerId;
stompMessage.FromDestination = dest;
@@ -0,0 +1,87 @@
// /*
// * Licensed to the Apache Software Foundation (ASF) under one or more
// * contributor license agreements. See the NOTICE file distributed with
// * this work for additional information regarding copyright ownership.
// * The ASF licenses this file to You 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.
// */
//
using System;
using Apache.NMS.Util;
using Apache.NMS.Stomp.Commands;

namespace Apache.NMS.Stomp
{
public class StompMessageTransformation : MessageTransformation
{
private Connection connection;

public StompMessageTransformation(Connection connection) : base()
{
this.connection = connection;
}

#region Creation Methods and Conversion Support Methods

protected override IMessage DoCreateMessage()
{
Message message = new Message();
message.Connection = this.connection;
return message;
}

protected override IBytesMessage DoCreateBytesMessage()
{
BytesMessage message = new BytesMessage();
message.Connection = this.connection;
return message;
}

protected override ITextMessage DoCreateTextMessage()
{
TextMessage message = new TextMessage();
message.Connection = this.connection;
return message;
}

protected override IStreamMessage DoCreateStreamMessage()
{
StreamMessage message = new StreamMessage();
message.Connection = this.connection;
return message;
}

protected override IMapMessage DoCreateMapMessage()
{
MapMessage message = new MapMessage();
message.Connection = this.connection;
return message;
}

protected override IObjectMessage DoCreateObjectMessage()
{
throw new NotSupportedException("Stomp Cannot process Object Messages");
}

protected override IDestination DoTransformDestination(IDestination destination)
{
return Destination.Transform(destination);
}

protected override void DoPostProcessMessage(IMessage message)
{
}

#endregion
}
}

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -55,27 +55,15 @@
<NoWarn>3016</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="Apache.NMS.Test, Version=1.4.0.2021, Culture=neutral, PublicKeyToken=82756feee3957618, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Apache.NMS\net-2.0\Apache.NMS.Test.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\NUnit\net-2.0\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="Apache.NMS, Version=1.4.0.2013, Culture=neutral, PublicKeyToken=82756feee3957618">
<SpecificVersion>False</SpecificVersion>
<HintPath>build\mono-2.0\debug\Apache.NMS.dll</HintPath>
</Reference>
<Reference Include="Apache.NMS.Stomp, Version=1.4.0.2015, Culture=neutral, PublicKeyToken=82756feee3957618">
<Reference Include="Apache.NMS.Test, Version=1.4.0.2025, Culture=neutral, PublicKeyToken=82756feee3957618">
<SpecificVersion>False</SpecificVersion>
<HintPath>build\mono-2.0\debug\Apache.NMS.Stomp.dll</HintPath>
<HintPath>lib\Apache.NMS\mono-2.0\Apache.NMS.Test.dll</HintPath>
</Reference>
<Reference Include="nunit.framework.extensions, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<Reference Include="nunit.framework, Version=2.5.5.10112, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\NUnit\mono-2.0\nunit.framework.extensions.dll</HintPath>
<HintPath>lib\NUnit\mono-2.0\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@@ -55,7 +55,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="Apache.NMS, Version=1.4.0.2021, Culture=neutral, PublicKeyToken=82756feee3957618">
<Reference Include="Apache.NMS, Version=1.4.0.2049, Culture=neutral, PublicKeyToken=82756feee3957618">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Apache.NMS\mono-2.0\Apache.NMS.dll</HintPath>
</Reference>
@@ -161,6 +161,7 @@
<Compile Include="src\main\csharp\State\SynchronizedObjects.cs" />
<Compile Include="src\main\csharp\IOException.cs" />
<Compile Include="src\main\csharp\Util\ThreadUtil.cs" />
<Compile Include="src\main\csharp\Util\StompMessageTransformation.cs" />
</ItemGroup>
<ItemGroup>
<None Include="keyfile\NMSKey.snk" />

0 comments on commit 2e651af

Please sign in to comment.