Skip to content

Commit 99f9820

Browse files
Add code for sending to ServiceBus in sample code
1 parent 2fffa7c commit 99f9820

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

sample/SampleApi/Program.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System.Text.Json;
12
using Atc.Azure.Messaging.EventHub;
3+
using Atc.Azure.Messaging.ServiceBus;
24

35
var builder = WebApplication.CreateBuilder(args);
46
builder.Services.AddEndpointsApiExplorer();
@@ -29,23 +31,33 @@
2931

3032
internal class SendDataHandler
3133
{
32-
private readonly IEventHubPublisher publisher;
34+
private readonly IEventHubPublisher eventHubPublisher;
35+
private readonly IServiceBusPublisher serviceBusPublisher;
3336

34-
public SendDataHandler(IEventHubPublisherFactory factory)
37+
public SendDataHandler(
38+
IEventHubPublisherFactory eventHubFactory,
39+
IServiceBusPublisher serviceBusPublisher)
3540
{
36-
publisher = factory.Create("ocpi");
41+
eventHubPublisher = eventHubFactory.Create("[existing eventhub]");
42+
this.serviceBusPublisher = serviceBusPublisher;
3743
}
3844

3945
public async Task<Response> Post(Request request)
4046
{
41-
await publisher
47+
await eventHubPublisher
4248
.PublishAsync(
4349
request,
4450
new Dictionary<string, string>(StringComparer.Ordinal)
4551
{
4652
{ "MessageType", "example" },
4753
});
4854

55+
await serviceBusPublisher
56+
.PublishAsync(
57+
"[existing topic|queue",
58+
"[session id or nothing]",
59+
JsonSerializer.Serialize(request));
60+
4961
return new Response(
5062
Guid.NewGuid().ToString("N"),
5163
request.A,

0 commit comments

Comments
 (0)