Skip to content

Commit 51f7a3e

Browse files
Simplify examples
1 parent cdfa9d2 commit 51f7a3e

File tree

2 files changed

+17
-41
lines changed

2 files changed

+17
-41
lines changed

README.md

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,7 @@ internal class FooPublisher
5252
}
5353

5454
public Task Publish(object message)
55-
=> publisher
56-
.PublishAsync(
57-
bar,
58-
new Dictionary<string, string>
59-
{
60-
{"messageType", nameof(message)}
61-
}
62-
)
55+
=> publisher.PublishAsync(message);
6356
}
6457
```
6558

@@ -78,17 +71,16 @@ internal class BarPublisher
7871
}
7972

8073
public Task Publish(object message)
81-
=> publisher
82-
.PublishAsync(
83-
"[existing servicebus topic]",
84-
"[session id or nothing]",
85-
JsonSerializer.Serialize(message));
74+
=> publisher.PublishAsync("[existing servicebus topic]", message);
8675
}
8776
```
8877

8978
Here's a full example of how to use the publishers above using a Minimal API setup (SwaggerUI enabled) with a single endpoint called `POST /data` that accepts a simple request body `{ "a": "string", "b": "string", "c": "string" }` which publishes the request to an EventHub and a ServiceBus topic
9079

9180
```csharp
81+
using Atc.Azure.Messaging.EventHub;
82+
using Atc.Azure.Messaging.ServiceBus;
83+
9284
var builder = WebApplication.CreateBuilder(args);
9385
builder.Services.AddEndpointsApiExplorer();
9486
builder.Services.AddSwaggerGen();
@@ -111,6 +103,11 @@ app.MapPost(
111103

112104
app.Run();
113105

106+
#pragma warning disable MA0048 // File name must match type name
107+
#pragma warning disable SA1649 // File name should match first type name
108+
#pragma warning disable MA0047 // Declare types in namespaces
109+
#pragma warning disable S3903 // Types should be defined in named namespaces
110+
114111
internal class SendDataHandler
115112
{
116113
private readonly IEventHubPublisher eventHubPublisher;
@@ -120,25 +117,15 @@ internal class SendDataHandler
120117
IEventHubPublisherFactory eventHubFactory,
121118
IServiceBusPublisher serviceBusPublisher)
122119
{
123-
eventHubPublisher = eventHubFactory.Create("[existing eventhub]");
120+
eventHubPublisher = eventHubFactory.Create("[existing eventhub");
124121
this.serviceBusPublisher = serviceBusPublisher;
125122
}
126123

127124
public async Task<Response> Post(Request request)
128125
{
129-
await eventHubPublisher
130-
.PublishAsync(
131-
request,
132-
new Dictionary<string, string>(StringComparer.Ordinal)
133-
{
134-
{ "MessageType", "example" },
135-
});
136-
137-
await serviceBusPublisher
138-
.PublishAsync(
139-
"[existing topic|queue",
140-
"[session id or nothing]",
141-
System.Text.Json.JsonSerializer.Serialize(request));
126+
await eventHubPublisher.PublishAsync(request);
127+
128+
await serviceBusPublisher.PublishAsync("existing topic|queue", request);
142129

143130
return new Response(
144131
Guid.NewGuid().ToString("N"),

sample/SampleApi/Program.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Text.Json;
21
using Atc.Azure.Messaging.EventHub;
32
using Atc.Azure.Messaging.ServiceBus;
43

@@ -38,25 +37,15 @@ public SendDataHandler(
3837
IEventHubPublisherFactory eventHubFactory,
3938
IServiceBusPublisher serviceBusPublisher)
4039
{
41-
eventHubPublisher = eventHubFactory.Create("[existing eventhub]");
40+
eventHubPublisher = eventHubFactory.Create("[existing eventhub");
4241
this.serviceBusPublisher = serviceBusPublisher;
4342
}
4443

4544
public async Task<Response> Post(Request request)
4645
{
47-
await eventHubPublisher
48-
.PublishAsync(
49-
request,
50-
new Dictionary<string, string>(StringComparer.Ordinal)
51-
{
52-
{ "MessageType", "example" },
53-
});
46+
await eventHubPublisher.PublishAsync(request);
5447

55-
await serviceBusPublisher
56-
.PublishAsync(
57-
"[existing topic|queue",
58-
"[session id or nothing]",
59-
JsonSerializer.Serialize(request));
48+
await serviceBusPublisher.PublishAsync("existing topic|queue", request);
6049

6150
return new Response(
6251
Guid.NewGuid().ToString("N"),

0 commit comments

Comments
 (0)