-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathExample.cs
50 lines (38 loc) · 1.08 KB
/
Example.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Grpc.Net.Client;
using Takenet.Deckard;
using var channel = GrpcChannel.ForAddress(
"localhost:8081",
// Example using Insecure credentials
new GrpcChannelOptions { Credentials = Grpc.Core.ChannelCredentials.Insecure }
);
var client = new Deckard.DeckardClient(channel);
// Create a new message
var message = new AddMessage{
Id = "1",
Queue = "queue",
};
message.Metadata.Add("key", "value");
var addRequest = new AddRequest();
addRequest.Messages.Add(message);
var addResponse = client.Add(addRequest);
if (addResponse.CreatedCount != 1)
{
Console.WriteLine("Error adding message");
Environment.Exit(1);
}
// Pull messages from the queue
var response = client.Pull(new PullRequest {
Queue = "queue",
Amount = 1
});
// Do something with the message
Console.WriteLine(response.Messages[0].Score);
// Ack message
client.Ack(new AckRequest {
Id = response.Messages[0].Id,
Queue = "queue",
// Remove the message from the queue
RemoveMessage: true,
// Lock message for 10 seconds before it can be pulled again
//LockMs = 10000
});