Skip to content

Commit 59c09df

Browse files
authored
Update README.md
1 parent fade5ee commit 59c09df

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

README.md

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,102 @@
1-
# HareIsle
1+
# HareIsle
2+
IPC .NET library powered by RabbitMQ. Provides RPC query, broadcast, and queue processing functionality.
3+
## Using
4+
Install NuGet package:
5+
```
6+
dotnet add package HareIsle
7+
```
8+
Add using derective:
9+
```cs
10+
using RabbitMQ.Client;
11+
using Usefull.HareIsle;
12+
```
13+
Create RabbitMq connection factory:
14+
```cs
15+
ConnectionFactory connectionFactory = new()
16+
{
17+
Uri = new Uri("amqp://user:pass@rabbithost:5672/"),
18+
ConsumerDispatchConcurrency = 10,
19+
AutomaticRecoveryEnabled = true,
20+
TopologyRecoveryEnabled = true,
21+
RequestedHeartbeat = TimeSpan.FromSeconds(10)
22+
};
23+
```
24+
### Scenario: broadcasting
25+
Create the broadcast message handler:
26+
```cs
27+
// RabbitMq connection
28+
using var connection = await connectionFactory.CreateConnectionAsync();
29+
// Message handler
30+
using var handler = new BroadcastHandler<SomeMessage>(
31+
"Handler actor ID", // ID of the actor on whose behalf the message is processed
32+
connection, // RabbitMq connection
33+
"Broadcast ID", // ID of the actor on whose behalf messages are broadcast
34+
message => // handling function
35+
{
36+
// do some handling
37+
});
38+
Console.ReadKey(); // message listening stops when press a key
39+
```
40+
Publish the broadcast message:
41+
```cs
42+
// Create the broadcast publisher
43+
using var emitter = new Emitter("Broadcast ID", connection);
44+
// Publish the message
45+
await emitter.BroadcastAsync(new SomeMessage
46+
{
47+
Message = "some text",
48+
Value = 123
49+
});
50+
```
51+
### Scenario: queue handling
52+
Create the queue handler:
53+
```cs
54+
// RabbitMq connection
55+
using var connection = await connectionFactory.CreateConnectionAsync();
56+
// Message handler
57+
using var handler = new QueueHandler<SomeMessage>(
58+
"Handler actor ID", // ID of the actor on whose behalf the message is processed
59+
connection, // RabbitMq connection
60+
"QueueName", // queue name
61+
5, // concurrency factor
62+
message => // handling function
63+
{
64+
// do some handling
65+
});
66+
Console.ReadKey(); // queue listening stops when press a key
67+
```
68+
Place the message in the queue:
69+
```cs
70+
using var emitter = new Emitter("SomeActorID", connection); // create the emmiter
71+
await emitter.DeclareQueueAsync("QueueName"); // declare the queue
72+
await emitter.EnqueueAsync("QueueName", new SomeMessage // send the message
73+
{
74+
Text = "some text"
75+
});
76+
```
77+
### Scenario: RPC
78+
Create the RPC handler:
79+
```cs
80+
// RabbitMq connection
81+
using var connection = await connectionFactory.CreateConnectionAsync();
82+
// RPC handler
83+
using var handler = new RpcHandler<Request, Response>(
84+
"Actor ID", // ID of the actor on whose behalf the RPC is processed
85+
connection, // RabbitMq connection
86+
5, // concurrency factor
87+
reques => // RPC handling function
88+
{
89+
// do some handling
90+
});
91+
Console.ReadKey(); // message listening stops when press a key
92+
```
93+
Make the RPC and get a response:
94+
```cs
95+
using var rpcClient = new RpcClient("ClientID", connection);
96+
var request = new Request
97+
{
98+
Value = 123,
99+
Text = "some text"
100+
};
101+
var response = await rpcClient.CallAsync<Request, Response>("Actor ID", request);
102+
```

0 commit comments

Comments
 (0)