Skip to content

Commit f2692af

Browse files
authored
Merge pull request #1 from rh-messaging/net-core-client
Initial net-core client implementation
2 parents 9a94bc7 + c5da65e commit f2692af

25 files changed

+3944
-16
lines changed

.gitignore

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
Sender/bin/
2-
Sender/obj/
3-
Receiver/bin/
4-
Receiver/obj/
5-
Connector/bin/
6-
Connector/obj/
7-
ClientLib/bin/
8-
ClientLib/obj/
9-
ClientUnitTests/bin/
10-
ClientUnitTests/obj/
11-
CliNetliteInstaller/bin/
12-
CliNetliteInstaller/obj/
1+
**/bin
2+
**/obj
133
.vs/
144
.vscode/
155
packages/

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
language: csharp
22
solution: cli-netlite.sln
3+
dotnet: 2.0.0
34

45
services:
56
- docker
67

78
install:
89
- nuget restore cli-netlite.sln
910
- nuget install NUnit.Runners -Version 2.6.4 -OutputDirectory testrunner
11+
- dotnet restore
12+
1013
script:
1114
# https://docs.travis-ci.com/user/docker/
1215
- docker pull enkeys/alpine-openjdk-amq7-snapshot
1316
- docker run --rm -v`pwd`/scripts:/mnt -p 5672:5672 -p 61616:61616 --entrypoint ash enkeys/alpine-openjdk-amq7-snapshot /mnt/entrypoint.sh amq7-server &
1417
- sleep 10
1518
- xbuild /p:Configuration=TravisCI cli-netlite.sln
16-
- mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe ./ClientUnitTests/bin/Debug/ClientUnitTests.dll
19+
- mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe ./ClientUnitTests/bin/Debug/ClientUnitTests.dll
20+
- dotnet build ./ClientLibNetCore
21+
- dotnet build ./NetCoreSender
22+
- dotnet build ./NetCoreReceiver
23+
- dotnet build ./NetCoreConnector
24+
- dotnet test ./NetCoreClientUnitTest/NetCoreClientUnitTest.csproj --verbosity normal

CliNetliteInstaller/Product.wxs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@
5757
<Component Id="NDesk.Options.dll">
5858
<File Id="NDesk.Options.dll" Source="..\ClientLib\bin\Debug\NDesk.Options.dll" KeyPath="yes" Checksum="yes"/>
5959
</Component>
60+
<Component Id="ClientLibNetCore.dll">
61+
<File Id="ClientLibNetCore.dll" Source="..\ClientLibNetCore\bin\Debug\netcoreapp2.0\ClientLibNetCore.dll" KeyPath="yes" Checksum="yes"/>
62+
</Component>
63+
<Component Id="NetCoreSender.dll">
64+
<File Id="SenderCoreExecutable.dll" Source="..\NetCoreSender\bin\Debug\netcoreapp2.0\cli-netlite-core-sender.dll" KeyPath="yes" Checksum="yes"/>
65+
</Component>
66+
<Component Id="NetCoreReceiver.dll">
67+
<File Id="ReceiverCoreExecutable.dll" Source="..\NetCoreReceiver\bin\Debug\netcoreapp2.0\cli-netlite-core-receiver.dll" KeyPath="yes" Checksum="yes"/>
68+
</Component>
69+
<Component Id="NetCoreConnector.dll">
70+
<File Id="ConnectorCoreExecutable.dll" Source="..\NetCoreConnector\bin\Debug\netcoreapp2.0\cli-netlite-core-connector.dll" KeyPath="yes" Checksum="yes"/>
71+
</Component>
6072
<Component Id="SetEnvPath"
6173
Guid="{016cb18d-0357-425b-90a8-caf1826ddee6}">
6274
<CreateFolder />
@@ -73,6 +85,10 @@
7385
<ComponentRef Id="SenderExe" />
7486
<ComponentRef Id="ReceiverExe" />
7587
<ComponentRef Id="ConnectorExe"/>
88+
<ComponentRef Id="ClientLibNetCore.dll"/>
89+
<ComponentRef Id="SenderCoreExecutable.dll"/>
90+
<ComponentRef Id="ConnectorCoreExecutable.dll"/>
91+
<ComponentRef Id="ReceiverCoreExecutable.dll"/>
7692
</Feature>
7793
</Fragment>
7894
</Wix>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="amqpnetlite" Version="2.0.0" />
9+
</ItemGroup>
10+
11+
</Project>

ClientLibNetCore/ConnectorClient.cs

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/*
2+
* Copyright 2017 Red Hat Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System;
18+
using System.Threading;
19+
using System.Collections.ObjectModel;
20+
using System.Text.RegularExpressions;
21+
22+
using Amqp;
23+
24+
namespace ClientLib
25+
{
26+
/// <summary>
27+
/// Connector client class
28+
/// </summary>
29+
public class ConnectorClient : CoreClient
30+
{
31+
/// <summary>
32+
/// Method for run connector
33+
/// </summary>
34+
/// <param name="args">cmd line arguments</param>
35+
public void Run(string[] args)
36+
{
37+
Collection<Connection> connections = new Collection<Connection>();
38+
Collection<Session> sessions = new Collection<Session>();
39+
Collection<SenderLink> senders = new Collection<SenderLink>();
40+
Collection<ReceiverLink> receivers = new Collection<ReceiverLink>();
41+
42+
ConnectorOptions options = new ConnectorOptions();
43+
44+
try
45+
{
46+
//parse args
47+
this.ParseArguments(args, options);
48+
49+
//create connections
50+
if (Regex.IsMatch(options.ObjCtrl, "[CESR]"))
51+
{
52+
53+
for (int i = 0; i < options.MsgCount; i++)
54+
{
55+
connections.Add(new Connection(new Address(options.Url)));
56+
}
57+
}
58+
59+
//request to create at least a session (connection needed)
60+
if (Regex.IsMatch(options.ObjCtrl, "[ESR]"))
61+
{
62+
try
63+
{
64+
foreach (Connection conn in connections)
65+
{
66+
sessions.Add(new Session(conn));
67+
}
68+
}
69+
catch (AmqpException ae)
70+
{
71+
Console.Error.WriteLine(ae.Message);
72+
for (int i = sessions.Count; i < connections.Count; i++)
73+
{
74+
sessions.Add(null);
75+
Environment.Exit(ReturnCode.ERROR_OTHER);
76+
}
77+
}
78+
79+
string address = options.Address;
80+
81+
if (address != String.Empty)
82+
{
83+
if (Regex.IsMatch(options.ObjCtrl, "[S]"))
84+
{
85+
try
86+
{
87+
int i = 0;
88+
foreach (Session s in sessions)
89+
{
90+
i++;
91+
if (s != null)
92+
senders.Add(new SenderLink(s, "sender" + i.ToString(), address));
93+
else
94+
senders.Add(null);
95+
}
96+
}
97+
catch (AmqpException ae)
98+
{
99+
Console.Error.WriteLine(ae.Message);
100+
for (int i = senders.Count; i < sessions.Count; i++)
101+
{
102+
senders.Add(null);
103+
}
104+
Environment.Exit(ReturnCode.ERROR_OTHER);
105+
}
106+
}
107+
if (Regex.IsMatch(options.ObjCtrl, "[R]"))
108+
{
109+
try
110+
{
111+
int i = 0;
112+
foreach (Session s in sessions)
113+
{
114+
i++;
115+
if (s != null)
116+
receivers.Add(new ReceiverLink(s, "tmp_rcv" + i.ToString(), address));
117+
else
118+
receivers.Add(null);
119+
}
120+
}
121+
catch (AmqpException ae)
122+
{
123+
Console.Error.WriteLine(ae.Message);
124+
for (int i = receivers.Count; i < sessions.Count; i++)
125+
{
126+
receivers.Add(null);
127+
}
128+
Environment.Exit(ReturnCode.ERROR_OTHER);
129+
}
130+
}
131+
}
132+
}
133+
this.exitCode = ReturnCode.ERROR_SUCCESS;
134+
}
135+
catch (ArgumentException ex)
136+
{
137+
this.ArgumentExceptionHandler(ex, options);
138+
}
139+
catch (Exception ex)
140+
{
141+
this.OtherExceptionHandler(ex, options);
142+
}
143+
finally
144+
{
145+
if (options.CloseSleep > 0)
146+
Thread.Sleep(options.CloseSleep);
147+
148+
foreach (ReceiverLink rec in receivers)
149+
{
150+
if (rec != null)
151+
{
152+
rec.Close();
153+
}
154+
}
155+
foreach (SenderLink sen in senders)
156+
{
157+
if (sen != null)
158+
{
159+
sen.Close();
160+
}
161+
}
162+
foreach (Session ses in sessions)
163+
{
164+
if (ses != null)
165+
{
166+
ses.Close();
167+
}
168+
}
169+
foreach (Connection c in connections)
170+
{
171+
if (c != null)
172+
{
173+
c.Close();
174+
}
175+
}
176+
}
177+
Environment.Exit(this.exitCode);
178+
}
179+
}
180+
}

0 commit comments

Comments
 (0)