Skip to content

Commit 9c2570b

Browse files
Ticket #113 : Add documentation amqp + websocket + sinkamqp + fix some issues
1 parent 97b5dd5 commit 9c2570b

18 files changed

Lines changed: 466 additions & 81 deletions

File tree

docs/documentation/eventmesh/pluginamqp.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ The ZIP file can be downloaded [here]().
2626

2727
## Quick start
2828

29-
Once you have an up and running EventMesh server with `ProtocolAmqp` plugin enabled, you can start using any client compliant with the AMQP 1.0 protocol.
29+
Once you have an up and running EventMesh server with `ProtocolAmqp` plugin enabled, you can start using any client compliant with the [AMQP 1.0 protocol](http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-complete-v1.0-os.pdf).
3030

3131
### Configure client and VPN
3232

3333
Before going further, a Virtual Private Network (VPN) and two clients must be configured.
34-
Those information will be used to publish message and subscribe to one or more topic.
34+
Those information will be used to publish message and subscribe to one topic.
3535

3636
Open a command prompt and create a topic named `default` :
3737

@@ -56,7 +56,7 @@ FaasNet.EventMeshCTL.CLI.exe add_client --vpn=default --identifier=subscribeClie
5656
If the plugin is not yet configured, it can be enabled like this
5757

5858
```
59-
FaasNet.EventMeshCTL.CLI.exe get_plugin_configuration --name=ProtocolAmqp
59+
FaasNet.EventMeshCTL.CLI.exe enable_plugin --name=ProtocolAmqp
6060
```
6161

6262
Its configuration can be updated either by [using CLI](cli.md) or by updating the configuration file `appsettings.json`.
@@ -69,7 +69,7 @@ When the configuration is finished, a client can be created and can start publis
6969

7070
The source code of this project can be found [here]().
7171

72-
### Create a client
72+
## Create a client
7373

7474
In this tutorial, we will explain how to create a C# client to publish message and subscribe to one topic `q1`.
7575

@@ -108,8 +108,11 @@ static void ReceiveMessage()
108108
var connection = new Connection(address);
109109
var session = new Session(connection);
110110
var receiver = new ReceiverLink(session, "receiver-link", "q1");
111-
var message = receiver.Receive();
112-
Console.WriteLine("Received " + message.Body.ToString());
111+
while(true)
112+
{
113+
var message = receiver.Receive();
114+
Console.WriteLine("Received " + message.Body.ToString());
115+
}
113116
});
114117
}
115118
```
@@ -127,7 +130,7 @@ Console.ReadLine();
127130

128131
Build the project and run.
129132

130-
The console application should displayed two messages :
133+
The console application must display two messages :
131134

132135
```
133136
Send Hello AMQP!
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# AMQP 1.0 sink
2+
3+
**Name**
4+
5+
SinkAMQP
6+
7+
**Description**
8+
9+
Consume events from AMQP 1.0 server.
10+
11+
**Link**
12+
13+
The ZIP file can be downloaded [here]().
14+
15+
**Options**
16+
17+
| Name | Description | Default value |
18+
| ----------------- | ----------------------------------------- | --------------------- |
19+
| jobId | Job identifier | AMQPTopic |
20+
| amqpHost | AMQP server host | 127.0.0.1 |
21+
| amqpPort | AMQP server port | 5672 |
22+
| amqpTopicName | Name of the topic exchange | amq.topic |
23+
| amqpUserName | AMQP username | guest |
24+
| amqpPassword | AMQP password | guest |
25+
| eventMeshUrl | EventMesh server URL | localhost |
26+
| eventMeshPort | EventMesh server Port | 4000 |
27+
| eventMeshVpn | EventMesh server VPN | default |
28+
| clientId | Client identifier used to publish message | publishClientId |
29+
30+
## Quick start
31+
32+
Once the plugin `SinkAMQP` is configured and enabled, you can deploy an AMQP 1.0 server such as RabbitMQ.
33+
34+
In this tutorial we will explain how to deploy a local RabbitMQ server with the plugin `rabbitmq_amqp1_0` enabled via Kubernetes.
35+
36+
### Deploy RabbitMQ via Kubernetes
37+
38+
Open a command prompt and install the RabbitMQ Cluster Kubernetes Operator
39+
40+
```
41+
kubectl apply -f "https://github.com/rabbitmq/cluster-operator/releases/latest/download/cluster-operator.yml"
42+
```
43+
44+
Deploy RabbitMQ
45+
46+
```
47+
kubectl apply -f "https://raw.githubusercontent.com/simpleidserver/FaasNet/master/src/Samples/FaasNet.EventMesh.AmqpSink/rabbitmq.yml"
48+
```
49+
50+
When the RabbitMQ server is running, fetch the default credentials username/password from the Kubernetes secrets.
51+
Both values are encoded in base64 and must be decoded.
52+
53+
```
54+
kubectl get secret hello-world-default-user -o jsonpath='{.data.user}'
55+
kubectl get secret hello-world-default-user -o jsonpath='{.data.password}'
56+
```
57+
58+
### Update plugin configuration
59+
60+
Always in a command prompt, use the CLI to update the username and password with the values obtained from the previous step.
61+
62+
```
63+
FaasNet.EventMeshCTL.CLI.exe update_plugin_configuration --name=SinkAMQP --key=amqpUserName --value=<USERNAME>
64+
FaasNet.EventMeshCTL.CLI.exe update_plugin_configuration --name=SinkAMQP --key=amqpPassword --value=<PASSWORD>
65+
```
66+
67+
Use the AMQP port `30007`.
68+
69+
```
70+
FaasNet.EventMeshCTL.CLI.exe update_plugin_configuration --name=SinkAMQP --key=amqpPort --value=30007
71+
```
72+
73+
And use the client identifier `publishClient`.
74+
75+
```
76+
FaasNet.EventMeshCTL.CLI.exe update_plugin_configuration --name=SinkAMQP --key=clientId --value=publishClient
77+
```
78+
79+
### Enable the plugin
80+
81+
Enable the plugin and restart the EventMesh server to take into account your changes.
82+
83+
```
84+
FaasNet.EventMeshCTL.CLI.exe enable_plugin --name=SinkAMQP
85+
```
86+
87+
Now the EventMesh server is running, it should be able to capture all the events coming from the exchange name `amq.topic`.
88+
You can publish some messages in RabbitMQ and check if they are captured by the EventMesh server.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO

docs/documentation/eventmesh/pluginwebsocket.md

Lines changed: 175 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,178 @@ The ZIP file can be downloaded [here]().
2222

2323
## Quick start
2424

25-
TODO
25+
Once you have an up and running EventMesh server with `ProtocolWebsocket` plugin enabled, you can start using any client compliant with the [WebSocket protocol](https://datatracker.ietf.org/doc/html/rfc6455).
26+
27+
### Configure client and VPN
28+
29+
Before going further, a Virtual Private Network (VPN) and two clients must be configured.
30+
Those information will be used to publish message and subscribe to one topic.
31+
32+
Open a command prompt and create a topic named `default` :
33+
34+
```
35+
FaasNet.EventMeshCTL.CLI.exe add_vpn --name=default
36+
```
37+
38+
Add a client `publishClient`, as the name suggests, it will be used to publish message.
39+
40+
```
41+
FaasNet.EventMeshCTL.CLI.exe add_client --vpn=default --identifier=publishClient --publish_enabled=true --subscription_enabled=false
42+
```
43+
44+
Add a client `subscribeClient`, this client will be used for subscription.
45+
46+
```
47+
FaasNet.EventMeshCTL.CLI.exe add_client --vpn=default --identifier=subscribeClient --publish_enabled=false --subscription_enabled=true
48+
```
49+
50+
### Configure the plugin
51+
52+
If the plugin is not yet configured, it can be enabled like this
53+
54+
```
55+
FaasNet.EventMeshCTL.CLI.exe enable_plugin --name=ProtocolWebsocket
56+
```
57+
58+
Its configuration can be updated either by [using CLI](cli.md) or by updating the configuration file `appsettings.json`.
59+
60+
Don't forget that the EventMesh server must be restarted, otherwise the changes are not taken into account.
61+
62+
When the configuration is finished, a client can be created and can start publishing message.
63+
64+
## Source code
65+
66+
The source code of this project can be found [here]().
67+
68+
## Create a client
69+
70+
In this tutorial, we will explain how to create a javascript client to publish message and subscribe to one topic.
71+
72+
Create an HTML page and add the following content :
73+
74+
```
75+
<!DOCTYPE html>
76+
<html xmlns="http://www.w3.org/1999/xhtml">
77+
<head>
78+
<title></title>
79+
<style>
80+
#messages {
81+
list-style-type: none;
82+
padding: 0px;
83+
margin: 0px;
84+
}
85+
86+
#messages > li {
87+
padding: 5px;
88+
border: 1px solid gray;
89+
}
90+
</style>
91+
</head>
92+
<body>
93+
<div>
94+
<h1>Publish</h1>
95+
<div>
96+
<div>
97+
<label>Content</label>
98+
<input type="text" id="messageTxt" />
99+
</div>
100+
<div>
101+
<label>Topic</label>
102+
<input type="text" id="messageTopic" />
103+
</div>
104+
<button id="sendMessage">Send</button>
105+
</div>
106+
</div>
107+
<div>
108+
<h1>Subscribe</h1>
109+
<div id="sub">
110+
<div>
111+
<label>Topic</label>
112+
<input type="text" id="subTopic" />
113+
</div>
114+
<button id="startSubscription">Start subscription</button>
115+
</div>
116+
<ul id="messages">
117+
118+
</ul>
119+
</div>
120+
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
121+
<script>
122+
const ws = new WebSocket("ws://localhost:2803");
123+
$(document).ready(function() {
124+
var initSubscription = function() {
125+
ws.onmessage = function(data) {
126+
$("#messages").append("<li>" + data.data + "</li>");
127+
};
128+
$("#startSubscription").click(function() {
129+
const subTopic = $("#subTopic").val();
130+
var directSubscribe = {
131+
requestType: "DIRECTLY_SUBSCRIBE",
132+
vpn: "default",
133+
clientId: "subscribeClient",
134+
filter: subTopic
135+
};
136+
const json = JSON.stringify(directSubscribe);
137+
ws.send(json);
138+
$("#sub").hide();
139+
});
140+
};
141+
var initPublish = function() {
142+
$("#sendMessage").click(function() {
143+
const msg = $("#messageTxt").val();
144+
const topic = $("#messageTopic").val();
145+
var publishMsg = {
146+
requestType: 'PUBLISH',
147+
vpn: 'default',
148+
id: 'id',
149+
subject: 'subject',
150+
topic: topic,
151+
clientId: 'publishClient',
152+
content: msg
153+
};
154+
const json = JSON.stringify(publishMsg);
155+
ws.send(json);
156+
$("#messageTxt").val('');
157+
$("#messageTopic").val('');
158+
});
159+
};
160+
initSubscription();
161+
initPublish();
162+
});
163+
</script>
164+
</body>
165+
</html>
166+
```
167+
168+
Open your preferred web browser and browse the HTML file.
169+
170+
There are two blocks displayed in the UI.
171+
172+
Under the `Subscribe` block, enter the topic name for example `q1` and click on the button `Start subscription` to start listening messages coming from the topic `q1`.
173+
174+
Under the `Publish` block, enter the topic name `q1`, write a message and click on the `Send` button.
175+
176+
The message will be transferred to the EventMesh server and will be displayed in the HTML page.
177+
178+
The websocket plugin accepts two types of request.
179+
180+
**Subscribe request**
181+
182+
| Property | Description | Default value |
183+
| ----------- | ----------------- | ------------------ |
184+
| requestType | Type of request | DIRECTLY_SUBSCRIBE |
185+
| vpn | VPN name | |
186+
| clientId | Client identifier | |
187+
| filter | | |
188+
189+
**Publish request**
190+
191+
| Property | Description | Default value |
192+
| ----------- | ---------------------------------------------------------------------------- | ------------- |
193+
| requestType | Type of request | PUBLISH |
194+
| vpn | VPN name | |
195+
| id | An identifier for the event | |
196+
| subject | This describes the subject of the event in the context of the event producer | |
197+
| topic | | |
198+
| clientId | Client identifier | |
199+
| content | Event data specific to the event type | |

src/EventMesh/FaasNet.EventMesh.Common/ConsoleHelper.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,12 @@ private static INodeHost BuildNodeHost(int port, bool isSeed = false)
253253
private static async Task StartAMQPSeed()
254254
{
255255
var serviceCollection = new ServiceCollection();
256-
serviceCollection.AddAMQPSeed(seed =>
257-
{
258-
seed.EventMeshPort = _seedPort;
259-
seed.Vpn = "default";
260-
seed.ClientId = "clientId";
261-
seed.EventMeshUrl = "localhost";
262-
}, amqp =>
256+
serviceCollection.AddAMQPSeed(amqp =>
263257
{
258+
amqp.EventMeshPort = _seedPort;
259+
amqp.Vpn = "default";
260+
amqp.ClientId = "clientId";
261+
amqp.EventMeshUrl = "localhost";
264262
amqp.AMQPUserName = "default_user_TBRVU8sYJmyVBXKeiTD";
265263
amqp.AMQPPassword = "d67v-U305u8Sh0dOwn02pTIuo2jsnLwY";
266264
amqp.AMQPPort = 30007;
@@ -285,14 +283,12 @@ private static async Task StartVpnBridgeSeed()
285283
private static async Task StartKafkaSeed()
286284
{
287285
var serviceCollection = new ServiceCollection();
288-
serviceCollection.AddKafkaSeed(seed =>
289-
{
290-
seed.EventMeshPort = _seedPort;
291-
seed.Vpn = "default";
292-
seed.ClientId = "clientId";
293-
seed.EventMeshUrl = "localhost";
294-
}, kafka =>
286+
serviceCollection.AddKafkaSeed(kafka =>
295287
{
288+
kafka.EventMeshPort = _seedPort;
289+
kafka.Vpn = "default";
290+
kafka.ClientId = "clientId";
291+
kafka.EventMeshUrl = "localhost";
296292
kafka.BootstrapServers = "localhost:29092";
297293
}).UseSinkRocksDB();
298294
var serviceProvider = serviceCollection.BuildServiceProvider();

0 commit comments

Comments
 (0)