Minor cleanup.

Added example of RequestReplyNmsTemplate
This commit is contained in:
markpollack
2009-06-16 19:53:15 +00:00
parent aca4e4f246
commit f7734690f4
9 changed files with 222 additions and 6 deletions

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 Spring.NmsQuickStart.Common.Data;
namespace Spring.NmsQuickStart.Client.Gateways
{
/// <summary>
///
/// </summary>
/// <remarks>
///
/// </remarks>
/// <author>Mark Pollack</author>
public interface ISyncStockService
{
TradeResponse Send(TradeRequest tradeRequest);
}
}

View File

@@ -0,0 +1,35 @@
#region License
/*
* Copyright 2002-2009 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 Spring.Messaging.Nms.Core;
using Spring.NmsQuickStart.Common.Data;
namespace Spring.NmsQuickStart.Client.Gateways
{
public class NmsSyncStockServiceGateway : NmsGatewaySupport, ISyncStockService
{
public TradeResponse Send(TradeRequest tradeRequest)
{
RequestReplyNmsTemplate requestReplyNmsTemplate = (RequestReplyNmsTemplate) NmsTemplate;
return (TradeResponse)requestReplyNmsTemplate.ConvertAndSendRequestReply(tradeRequest);
}
}
}

View File

@@ -0,0 +1,56 @@
#region License
/*
* Copyright 2002-2009 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;
using Spring.Messaging.Nms.Core;
namespace Spring.NmsQuickStart.Client.Gateways
{
/// <summary>
/// Not used in the example application but included to show how one could layer on top of
/// NMS a synchronous request reply interaction. This implementation uses temporary queues but
/// another approach would be to use a permanent queue with a message selector unique to the request.
/// </summary>
public class RequestReplyNmsTemplate : NmsTemplate
{
public object ConvertAndSendRequestReply(object objectToSend)
{
return Execute(delegate(ISession session, IMessageProducer producer)
{
ITemporaryQueue tempQueue = null;
try
{
tempQueue = session.CreateTemporaryQueue();
this.ConvertAndSendWithDelegate(objectToSend, delegate(IMessage message)
{
message.NMSReplyTo =
tempQueue;
return message;
});
return ReceiveAndConvert(tempQueue);
}
finally
{
if (tempQueue != null) session.DeleteDestination(tempQueue);
}
});
}
}
}

View File

@@ -1,4 +1,22 @@
#region License
/*
* Copyright 2002-2009 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 System.Collections;
using Common.Logging;

View File

@@ -1,3 +1,23 @@
#region License
/*
* Copyright 2002-2009 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 System;
using System.Threading;
using System.Windows.Forms;

View File

@@ -49,7 +49,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Gateways\IStockService.cs" />
<Compile Include="Gateways\NmsStockServiceGateway.cs" />
<Compile Include="Gateways\NmsStockServiceGateway.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Gateways\RequestReplyNmsTemplate.cs" />
<Compile Include="Handlers\StockAppHandler.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@@ -1,3 +1,22 @@
#region License
/*
* Copyright 2002-2009 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 System.Collections;
@@ -6,13 +25,15 @@ using Spring.NmsQuickStart.Common.Data;
namespace Spring.NmsQuickStart.Client.UI
{
/// <summary>
/// Handles requests from the UI and forwards them to the remote service. Messages recieved from
/// the service routed through this controller to update the UI.
/// </summary>
public class StockController
{
private StockForm stockForm;
private IStockService stockService;
public StockForm StockForm
{
@@ -38,8 +59,7 @@ namespace Spring.NmsQuickStart.Client.UI
tradeRequest.UserName = "Joe Trader";
stockService.Send(tradeRequest);
}
}
public void UpdateMarketData(IDictionary marketDataDict)
{

View File

@@ -1,3 +1,23 @@
#region License
/*
* Copyright 2002-2009 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 System;
using System.Collections;
using System.Windows.Forms;
@@ -34,7 +54,7 @@ namespace Spring.NmsQuickStart.Client.UI
//In this simple example no data is collected from the view.
//Instead a hardcoded trade request is created in the controller.
tradeRequestStatusTextBox.Text = "Request Pending...";
stockController.SendTradeRequest();
stockController.SendTradeRequest();
log.Info("Sent trade request.");
}
@@ -56,6 +76,11 @@ namespace Spring.NmsQuickStart.Client.UI
}));
}
private void OnPortfolioRequest(object sender, EventArgs e)
{
MessageBox.Show("Get Portfolio operation not yet implemented.", "NmsQuickStart");
}
}
}

View File

@@ -63,6 +63,7 @@ namespace Spring.NmsQuickStart.Client.UI
this.button1.TabIndex = 2;
this.button1.Text = "Get Portfolio";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.OnPortfolioRequest);
//
// portfolioListBox
//