Skip to content

Commit 1cfe8c2

Browse files
committed
Implement OrdersServiceProxy
1 parent f4c4ae5 commit 1cfe8c2

5 files changed

Lines changed: 62 additions & 6 deletions

File tree

InterProcessCommunication/TradingApp/.Notes/PresentationScript.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ <h4 id="implement-proxies-to-call-the-services-as-a-rest-api">8. Implement proxi
193193
<ul>
194194
<li><code>ConsoleUi</code> loads service implementations AND / OR proxies
195195
<ul>
196-
<li>if we comment out the implementations only proxies are loaded =&gt; always inter-process communication</li>
196+
<li>if we comment out the load of the modules with implementation (in AppBoot bootstrapp) only proxies are loaded =&gt; always inter-process communication</li>
197197
<li><code>ConsoleUi</code> may act like a FE app if does not load service implementations.
198198
<ul>
199199
<li>It always calls services as inter-proc</li>
@@ -208,11 +208,12 @@ <h4 id="implement-proxies-to-call-the-services-as-a-rest-api">8. Implement proxi
208208
</li>
209209
<li>If for one service (interface) both the implementation and the proxy is deployed, then the last one AppBoot finds orverwrites the previous
210210
<ul>
211-
<li>non deterministic
211+
<li><strong>non deterministic!</strong>
212212
<ul>
213213
<li>even if the real implementation is deployed, it may not be used</li>
214-
<li>ex1: <code>ConsoleUi</code> loads the <code>QuotationServices.dll</code> and <code>PortfolioService</code> we would expect a <em>in-process</em> communication
214+
<li>ex1: (to have this demoed we might need to comment our the <code>PortfolioServiceProxy</code> othewise the non-deterministic behavior may make this tricky to demo)
215215
<ul>
216+
<li><code>ConsoleUi</code> loads the <code>QuotationServices.dll</code> and <code>PortfolioService.dll</code> we would expect a <em>in-process</em> communication</li>
216217
<li>but! the <code>PortfolioService</code> may get a proxy to call the <code>QuotationService</code> this result in a <em>inter-process</em> communitcation between <code>PortfolioSerivce</code> and <code>QuotationService</code></li>
217218
</ul>
218219
</li>

InterProcessCommunication/TradingApp/.Notes/PresentationScript.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,16 @@ class QuotationService : IQuotationService
138138

139139
**Points:**
140140
- `ConsoleUi` loads service implementations AND / OR proxies
141-
- if we comment out the implementations only proxies are loaded => always inter-process communication
141+
- if we comment out the load of the modules with implementation (in AppBoot bootstrapp) only proxies are loaded => always inter-process communication
142142
- `ConsoleUi` may act like a FE app if does not load service implementations.
143143
- It always calls services as inter-proc
144144
- just through deployment `ConsoleUi` may call services *in-process* or *inter-process*
145145
- play w/ `PortfolioService` and w/ `QuotationService`
146146
- If for one service (interface) both the implementation and the proxy is deployed, then the last one AppBoot finds orverwrites the previous
147-
- non deterministic
147+
- **non deterministic!**
148148
- even if the real implementation is deployed, it may not be used
149-
- ex1: `ConsoleUi` loads the `QuotationServices.dll` and `PortfolioService` we would expect a *in-process* communication
149+
- ex1: (to have this demoed we might need to comment our the `PortfolioServiceProxy` othewise the non-deterministic behavior may make this tricky to demo)
150+
- `ConsoleUi` loads the `QuotationServices.dll` and `PortfolioService.dll` we would expect a *in-process* communication
150151
- but! the `PortfolioService` may get a proxy to call the `QuotationService` this result in a *inter-process* communitcation between `PortfolioSerivce` and `QuotationService`
151152
- ex2:
152153
- `ConsoleUi` loads only proxies, the communication between `PortfolioSerivce` and `QuotationService` happens on the `ConsoleHost` only, in process!

InterProcessCommunication/TradingApp/ConsoleUi/App.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
<appSettings>
77
<add key="IPortfolioService_Address" value="http://localhost:9000/"/>
88
<add key="IQuotationService_Address" value="http://localhost:9000/"/>
9+
<add key="IOrdersService_Address" value="http://localhost:9000/"/>
910
</appSettings>
1011
</configuration>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Web;
4+
using Contracts.Sales.Services;
5+
using iQuarc.AppBoot;
6+
7+
namespace Proxies
8+
{
9+
[Service(typeof(IOrdersService))]
10+
class OrdersServiceProxy : IOrdersService
11+
{
12+
public void PlaceSellLimitOrder(string securityCode, decimal sellingPrice, DateTime validUntil)
13+
{
14+
using (HttpClient client = HttpHelpers.CreateNewClient<IOrdersService>())
15+
{
16+
string path = HttpHelpers.GetServicePath<IOrdersService>("PlaceSellLimitOrder");
17+
string uri = $"{path}?securityCode={securityCode}&sellingPrice={sellingPrice}&validUntil={validUntil}";
18+
HttpResponseMessage response = client.PostAsync(uri, new StringContent(string.Empty)).Result;
19+
if (!response.IsSuccessStatusCode)
20+
throw new HttpException((int)response.StatusCode, response.Content.ReadAsStringAsync().Result);
21+
}
22+
}
23+
24+
public void PlaceBuyLimitOrder(string securityCode, decimal buyingPrice, DateTime validUntil)
25+
{
26+
using (HttpClient client = HttpHelpers.CreateNewClient<IOrdersService>())
27+
{
28+
string path = HttpHelpers.GetServicePath<IOrdersService>("PlaceBuyLimitOrder");
29+
string uri = $"{path}?securityCode={securityCode}&buyingPrice={buyingPrice}&validUntil={validUntil}";
30+
HttpResponseMessage response = client.PostAsync(uri, new StringContent(string.Empty)).Result;
31+
if (!response.IsSuccessStatusCode)
32+
throw new HttpException((int)response.StatusCode, response.Content.ReadAsStringAsync().Result);
33+
}
34+
}
35+
36+
public LimitOrder[] GetLimitOrders()
37+
{
38+
using (HttpClient client = HttpHelpers.CreateNewClient<IOrdersService>())
39+
{
40+
string path = HttpHelpers.GetServicePath<IOrdersService>("GetLimitOrders");
41+
HttpResponseMessage response = client.GetAsync(path).Result;
42+
if (response.IsSuccessStatusCode)
43+
{
44+
LimitOrder[] value = response.Content.ReadAsAsync<LimitOrder[]>().Result;
45+
return value;
46+
}
47+
48+
throw new HttpException((int)response.StatusCode, response.Content.ReadAsStringAsync().Result);
49+
}
50+
}
51+
}
52+
}

InterProcessCommunication/TradingApp/Infrastructure/Proxies/Proxies.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
</ItemGroup>
6161
<ItemGroup>
6262
<Compile Include="HttpHelpers.cs" />
63+
<Compile Include="OrdersServiceProxy.cs" />
6364
<Compile Include="PortfolioServiceProxy.cs" />
6465
<Compile Include="Properties\AssemblyInfo.cs" />
6566
<Compile Include="ProxiesModule.cs" />

0 commit comments

Comments
 (0)