Skip to content

Commit 30d0042

Browse files
committed
Update full duplex sample
1 parent 0c47e1e commit 30d0042

File tree

5 files changed

+28
-31
lines changed

5 files changed

+28
-31
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
using System.Threading.Tasks;
2-
using NServiceBus;
3-
using Microsoft.Extensions.Logging;
1+
using NServiceBus;
2+
using System;
3+
using System.Threading.Tasks;
44

55
#region DataResponseMessageHandler
6-
class DataResponseMessageHandler(ILogger<DataResponseMessageHandler> logger) :
6+
class DataResponseMessageHandler() :
77
IHandleMessages<DataResponseMessage>
88
#endregion
99
{
1010
public Task Handle(DataResponseMessage message, IMessageHandlerContext context)
1111
{
12-
logger.LogInformation("Response received with description: {Description}", message.String);
12+
Console.WriteLine($"Response received with description: {message.String}");
1313
return Task.CompletedTask;
1414
}
1515
}
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1+
using System;
12
using System.Threading.Tasks;
23
using NServiceBus;
3-
using Microsoft.Extensions.Logging;
44

55
#region RequestDataMessageHandler
6-
public class RequestDataMessageHandler(ILogger<RequestDataMessageHandler> logger) :
6+
7+
public class RequestDataMessageHandler () :
78
IHandleMessages<RequestDataMessage>
89
#endregion
910
{
1011
public async Task Handle(RequestDataMessage message, IMessageHandlerContext context)
1112
{
12-
logger.LogInformation("Received request {DataId}.", message.DataId);
13-
logger.LogInformation("String received: {Description}.", message.String);
13+
Console.WriteLine($"Received request {message.DataId}.");
14+
Console.WriteLine($"String received: {message.String}.");
1415

1516
#region DataResponseReply
1617

17-
var response = new DataResponseMessage(message.DataId, message.String);
18+
var response = new DataResponseMessage
19+
{
20+
DataId = message.DataId,
21+
String = message.String
22+
};
1823

1924
await context.Reply(response);
2025

2126
#endregion
2227
}
28+
2329
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
using System.Threading.Tasks;
2-
using NServiceBus;
3-
using Microsoft.Extensions.Logging;
1+
using NServiceBus;
2+
using System;
3+
using System.Threading.Tasks;
44

55
#region DataResponseMessageHandler
6-
class DataResponseMessageHandler(ILogger<DataResponseMessageHandler> logger) :
6+
class DataResponseMessageHandler() :
77
IHandleMessages<DataResponseMessage>
88
#endregion
99
{
1010
public Task Handle(DataResponseMessage message, IMessageHandlerContext context)
1111
{
12-
logger.LogInformation("Response received with description: {Description}", message.String);
12+
Console.WriteLine($"Response received with description: {message.String}");
1313
return Task.CompletedTask;
1414
}
1515
}

samples/fullduplex/Core_9/Server/RequestDataMessageHandler.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1+
using System;
12
using System.Threading.Tasks;
23
using NServiceBus;
3-
using Microsoft.Extensions.Logging;
44

55
#region RequestDataMessageHandler
66

7-
public class RequestDataMessageHandler (ILogger<RequestDataMessageHandler> logger) :
7+
public class RequestDataMessageHandler () :
88
IHandleMessages<RequestDataMessage>
99
#endregion
1010
{
11-
1211
public async Task Handle(RequestDataMessage message, IMessageHandlerContext context)
1312
{
14-
logger.LogInformation("Received request {DataId}.", message.DataId);
15-
logger.LogInformation("String received: {Description}.", message.String);
13+
Console.WriteLine($"Received request {message.DataId}.");
14+
Console.WriteLine($"String received: {message.String}.");
1615

1716
#region DataResponseReply
1817

samples/fullduplex/sample.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Full Duplex
33
summary: Using full-duplex and request/response communication.
4-
reviewed: 2024-02-28
4+
reviewed: 2026-01-05
55
component: Core
66
redirects:
77
- nservicebus/full-duplex-sample
@@ -30,11 +30,7 @@ The client console has an input loop:
3030

3131
snippet: ClientLoop
3232

33-
This code performs the following action every time the 'Enter' key is pressed:
34-
35-
* A new GUID is created and then set in the outgoing headers of the bus using the "Test" key.
36-
* The bus sends a `RequestDataMessage `whose DataId property is set to the same `Guid` and whose `String` property is set to an XML fragment.
37-
* A callback is registered and invoked when a response arrives to the request sent. In the callback, the values of several headers are written to the console.
33+
This code sends a message with a new `Guid` and a string value every time the 'Enter' key is pressed.
3834

3935
### Server
4036

@@ -48,11 +44,7 @@ The `Handle` method of this class contains this:
4844

4945
snippet: DataResponseReply
5046

51-
Finally, the bus replies with the response message, sending it to the InputQueue specified in the `MsmqTransportConfig` section in the app.config of the `Client` endpoint. The bus knows to send the responses to where the message is sent every time it sends a message from the queue.
52-
53-
When configuring the routing in the bus, continue with the premise of regular request/response communication such that clients need to know where the server is, but servers do not need to know about clients.
54-
55-
Look back at `ClientEndpoint.cs` to see that it gets the header information from the handler on the server.
47+
Finally, the bus replies with the response message. The bus knows to send the responses to where the message was sent from, every time it receives a message from the queue.
5648

5749
Open `DataResponseMessageHandler.cs` in the `Client` project and find a class whose signature looks similar to the message handler on the server:
5850

0 commit comments

Comments
 (0)