nms quickstart example development

This commit is contained in:
markpollack
2008-08-08 20:09:50 +00:00
parent ac8e34dc6a
commit e58917af3b
22 changed files with 235 additions and 35 deletions

View File

@@ -24,7 +24,7 @@ using Spring.NmsQuickStart.Common.Data;
namespace Spring.NmsQuickStart.Client.Gateways
{
public interface IStockServiceGateway
public interface IStockService
{
void Send(TradeRequest tradeRequest);
}

View File

@@ -8,7 +8,7 @@ using Spring.Objects.Factory;
namespace Spring.NmsQuickStart.Client.Gateways
{
public class NmsStockServiceGateway : NmsGatewaySupport, IStockServiceGateway, IInitializingObject
public class NmsStockServiceGateway : NmsGatewaySupport, IStockService, IInitializingObject
{
private IDestination defaultReplyToQueue;

View File

@@ -34,10 +34,10 @@ namespace Spring.NmsQuickStart.Client.Handlers
}
public void Handle(Trade trade)
public void Handle(TradeResponse tradeResponse)
{
log.Info(string.Format("Received trade. Ticker = {0}, Price = {1}", trade.Ticker, trade.Price));
stockController.UpdateTrade(trade);
log.Info(string.Format("Received trade resonse. Ticker = {0}, Price = {1}", tradeResponse.Ticker, tradeResponse.Price));
stockController.UpdateTrade(tradeResponse);
}
public void Handle(object catchAllObject)

View File

@@ -48,7 +48,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Gateways\IStockServiceGateway.cs" />
<Compile Include="Gateways\IStockService.cs" />
<Compile Include="Gateways\NmsStockServiceGateway.cs" />
<Compile Include="Handlers\StockAppHandler.cs" />
<Compile Include="Program.cs" />

View File

@@ -10,7 +10,7 @@ namespace Spring.NmsQuickStart.Client.UI
{
private StockForm stockForm;
private IStockServiceGateway stockServiceGateway;
private IStockService stockService;
@@ -20,10 +20,10 @@ namespace Spring.NmsQuickStart.Client.UI
set { stockForm = value; }
}
public IStockServiceGateway StockServiceGateway
public IStockService StockService
{
get { return stockServiceGateway; }
set { stockServiceGateway = value; }
get { return stockService; }
set { stockService = value; }
}
public void SendTradeRequest()
@@ -37,7 +37,7 @@ namespace Spring.NmsQuickStart.Client.UI
tradeRequest.Ticker = "CSCO";
tradeRequest.UserName = "Joe Trader";
stockServiceGateway.Send(tradeRequest);
stockService.Send(tradeRequest);
}
@@ -46,9 +46,9 @@ namespace Spring.NmsQuickStart.Client.UI
stockForm.UpdateMarketData(marketDataDict);
}
public void UpdateTrade(Trade trade)
public void UpdateTrade(TradeResponse tradeResponse)
{
stockForm.UpdateTrade(trade);
stockForm.UpdateTrade(tradeResponse);
}
}

View File

@@ -38,7 +38,7 @@ namespace Spring.NmsQuickStart.Client.UI
log.Info("Sent trade request.");
}
public void UpdateTrade(Trade trade)
public void UpdateTrade(TradeResponse trade)
{
Invoke(new MethodInvoker(
delegate

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!--This file is auto-generated by the XML Schema Designer. It holds layout information for components on the designer surface.-->
<XSDDesignerLayout Style="LeftRight" />

View File

@@ -22,16 +22,20 @@ namespace Spring.NmsQuickStart.Common.Data {
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.springframework.net/nms/common/2008-08-05")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.springframework.net/nms/common/2008-08-05", IsNullable=false)]
public partial class Trade {
public partial class TradeResponse {
private string tickerField;
private string quantityField;
private long quantityField;
private decimal priceField;
private string orderTypeField;
private bool errorField;
private string errorMessageField;
/// <remarks/>
public string Ticker {
get {
@@ -43,8 +47,7 @@ namespace Spring.NmsQuickStart.Common.Data {
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="integer")]
public string Quantity {
public long Quantity {
get {
return this.quantityField;
}
@@ -72,5 +75,25 @@ namespace Spring.NmsQuickStart.Common.Data {
this.orderTypeField = value;
}
}
/// <remarks/>
public bool Error {
get {
return this.errorField;
}
set {
this.errorField = value;
}
}
/// <remarks/>
public string ErrorMessage {
get {
return this.errorMessageField;
}
set {
this.errorMessageField = value;
}
}
}
}

View File

@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.springframework.net/nms/common/2008-08-05">
<xs:element name="Trade">
<xs:element name="TradeResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="Ticker" type="xs:string"/>
<xs:element name="Quantity" type="xs:integer"/>
<xs:element name="Quantity" type="xs:long"/>
<xs:element name="Price" type="xs:decimal"/>
<xs:element name="OrderType" type="xs:string"/>
<xs:element name="Error" type="xs:boolean"/>
<xs:element name="ErrorMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!--This file is auto-generated by the XML Schema Designer. It holds layout information for components on the designer surface.-->
<XSDDesignerLayout Style="LeftRight" />

View File

@@ -1,2 +1,2 @@
xsd.exe -c -l:c# -n:Spring.NmsQuickStart.Common.Data Trade.xsd
xsd.exe -c -l:c# -n:Spring.NmsQuickStart.Common.Data TradeResponse.xsd
xsd.exe -c -l:c# -n:Spring.NmsQuickStart.Common.Data TradeRequest.xsd

View File

@@ -44,8 +44,8 @@
<Compile Include="Converters\ITypeMapper.cs" />
<Compile Include="Converters\TypeMapper.cs" />
<Compile Include="Converters\XmlMessageConverter.cs" />
<Compile Include="Data\Trade.cs">
<DependentUpon>Trade.xsd</DependentUpon>
<Compile Include="Data\TradeResponse.cs">
<DependentUpon>TradeResponse.xsd</DependentUpon>
</Compile>
<Compile Include="Data\TradeRequest.cs">
<DependentUpon>TradeRequest.xsd</DependentUpon>
@@ -71,12 +71,18 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Data\Trade.xsd">
<None Include="Data\TradeResponse.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Data\TradeResponse.xsx">
<DependentUpon>TradeResponse.xsd</DependentUpon>
</None>
<None Include="Data\TradeRequest.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Data\TradeRequest.xsx">
<DependentUpon>TradeRequest.xsd</DependentUpon>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -15,18 +15,29 @@
<property name="MessageConverter" ref="XmlMessageConverter"/>
</object>
<object name="MarketDataGateway" type="Spring.NmsQuickStart.Server.Gateways.MarketDataGateway, Spring.NmsQuickStart.Server">
<property name="NmsTemplate" ref="NmsTemplate"/>
</object>
<!-- Consume messages on queue APP.STOCK.REQUEST -->
<!--
<nms:listener-container connection-factory="ConnectionFactory" concurrency="10">
<nms:listener ref="MessageListenerAdapter" destination="APP.STOCK.REQUEST" />
</nms:listener-container>
-->
<object id="MessageListenerContainer" type="Spring.Messaging.Nms.Listener.SimpleMessageListenerContainer, Spring.Messaging.Nms">
<property name="ConnectionFactory" ref="ConnectionFactory"/>
<property name="DestinationName" value="APP.STOCK.REQUEST"/>
<property name="ConcurrentConsumers" value="1"/>
<property name="MessageListener" ref="MessageListenerAdapter"/>
<property name="ExceptionListener" ref="LoggingExceptionListener"/>
</object>
<object name="LoggingExceptionListener" type="Spring.NmsQuickStart.Server.Handlers.LoggingExceptionListener, Spring.NmsQuickStart.Server"/>
<!-- Plain object message handler -->
<object id="MessageListenerAdapter" type="Spring.Messaging.Nms.Listener.Adapter.MessageListenerAdapter, Spring.Messaging.Nms">
<property name="HandlerObject" ref="StockAppHandler"/>

View File

@@ -0,0 +1,7 @@
namespace Spring.NmsQuickStart.Server.Gateways
{
public interface IMarketDataService
{
void SendMarketData();
}
}

View File

@@ -6,15 +6,15 @@ using Spring.Messaging.Nms.Core;
namespace Spring.NmsQuickStart.Server.Gateways
{
public class MarketDataGateway : NmsGatewaySupport
public class MarketDataServiceGateway : NmsGatewaySupport, IMarketDataService
{
private static readonly ILog log = LogManager.GetLogger(typeof (MarketDataGateway));
private static readonly ILog log = LogManager.GetLogger(typeof (MarketDataServiceGateway));
private readonly Random random;
private int sleepTimeInSeconds = 2;
public MarketDataGateway()
public MarketDataServiceGateway()
{
random = new Random();
}

View File

@@ -0,0 +1,26 @@
using System;
using Common.Logging;
using Spring.Messaging.Nms.Core;
namespace Spring.NmsQuickStart.Server.Handlers
{
public class LoggingExceptionListener : IExceptionListener
{
#region Logging
private readonly ILog logger = LogManager.GetLogger(typeof(LoggingExceptionListener));
#endregion
/// <summary>
/// Called when there is an exception in message processing.
/// </summary>
/// <param name="exception">The exception.</param>
public void OnException(Exception exception)
{
logger.Info("********* Caught exception *************", exception);
}
}
}

View File

@@ -1,7 +1,9 @@
using System.Collections;
using Common.Logging;
using Spring.NmsQuickStart.Common.Data;
using Spring.NmsQuickStart.Server.Services;
namespace Spring.NmsQuickStart.Server.Handlers
{
@@ -10,11 +12,28 @@ namespace Spring.NmsQuickStart.Server.Handlers
private static readonly ILog log = LogManager.GetLogger(typeof(StockAppHandler));
private IExecutionVenueService executionVenueService;
public Trade Handle(TradeRequest tradeRequest)
private ICreditCheckService creditCheckService;
private ITradingService tradingService;
public TradeResponse Handle(TradeRequest tradeRequest)
{
log.Info("Received TradeRequest");
return new Trade();
TradeResponse tradeResponse;
IList errors = new ArrayList();
if (creditCheckService.CanExecute(tradeRequest, errors))
{
tradeResponse = executionVenueService.ExecuteTradeRequest(tradeRequest);
tradingService.ProcessTrade(tradeRequest, tradeResponse);
}
else
{
tradeResponse = new TradeResponse();
tradeResponse.Error = true;
tradeResponse.ErrorMessage = errors[0].ToString();
}
return tradeResponse;
}
}
}

View File

@@ -14,11 +14,11 @@ namespace Spring.NmsQuickStart.Server
// Using Spring's IoC container
ContextRegistry.GetContext(); // Force Spring to load configuration
Console.Out.WriteLine("Server listening...");
MarketDataGateway marketDataGateway =
ContextRegistry.GetContext().GetObject("MarketDataGateway") as MarketDataGateway;
ThreadStart job = new ThreadStart(marketDataGateway.SendMarketData);
IMarketDataService marketDataService =
ContextRegistry.GetContext().GetObject("MarketDataGateway") as MarketDataServiceGateway;
ThreadStart job = new ThreadStart(marketDataService.SendMarketData);
Thread thread = new Thread(job);
thread.Start();
//thread.Start();
Console.Out.WriteLine("--- Press <return> to quit ---");
Console.ReadLine();
}

View File

@@ -0,0 +1,33 @@
#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 System.Collections;
using Spring.NmsQuickStart.Common.Data;
namespace Spring.NmsQuickStart.Server.Services
{
public interface ICreditCheckService
{
bool CanExecute(TradeRequest tradeRequest, IList errors);
}
}

View File

@@ -0,0 +1,31 @@
#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.Server.Services
{
public interface IExecutionVenueService
{
TradeResponse ExecuteTradeRequest(TradeRequest request);
}
}

View File

@@ -0,0 +1,31 @@
#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.Server.Services
{
public interface ITradingService
{
void ProcessTrade(TradeRequest request, TradeResponse response);
}
}

View File

@@ -45,10 +45,15 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Gateways\MarketDataGateway.cs" />
<Compile Include="Gateways\IMarketDataService.cs" />
<Compile Include="Gateways\MarketDataServiceGateway.cs" />
<Compile Include="Handlers\LoggingExceptionListener.cs" />
<Compile Include="Handlers\StockAppHandler.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\ICreditCheckService.cs" />
<Compile Include="Services\IExecutionVenueService.cs" />
<Compile Include="Services\ITradingService.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />