-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDK generates different message format than dapr api for outbox pattern and message can't be consumed #1332
Comments
For repro I can confirm I tested with the Runtime RC 5 and v1.14.0-rc02 for dotnet sdk. |
/assign |
I think the exception generated by my program when I use the dapr publish command depends on the different serialization of the Exception: DAPR VERSION: 1.14.4 In my case when i publish an event from a .NET program it generates the following event: {
"data": {
"machine": "s17",
"text": "s15"
},
"datacontenttype": "application/json",
"id": "3f1df251-ee89-49e2-9b60-a2141916494d",
"pubsubname": "test-pub-sub",
"source": "dapr-pub-sub-ui",
"specversion": "1.0",
"time": "2024-09-18T22:58:58+02:00",
"topic": "tests",
"traceid": "00-ed23265a9f2081ab922ba5480b9c4a43-9849ed44dbb8cc62-00",
"traceparent": "00-ed23265a9f2081ab922ba5480b9c4a43-9849ed44dbb8cc62-00",
"tracestate": "",
"type": "com.dapr.event.sent"
} But when i use the command: {
"data": "{machine: s17, text: s15 }",
"datacontenttype": "application/json",
"id": "5ab8faa6-8713-4a47-a661-731272de3caa",
"pubsubname": "test-pub-sub",
"source": "dapr-pub-sub-ui",
"specversion": "1.0",
"time": "2024-09-18T22:57:21+02:00",
"topic": "tests",
"traceid": "00-f16c74a03cb9e2faf9622a794c915bca-bdae99cceba9fc24-01",
"traceparent": "00-f16c74a03cb9e2faf9622a794c915bca-bdae99cceba9fc24-01",
"tracestate": "",
"type": "com.dapr.event.sent"
} Seem dapr doesn't respect the |
@m3nax I think the issue you describe here is something different since you are interacting with the Pub/Sub building block directly. |
You are right, i will open an issue in dapr/dapr repo. |
@fabistb can this be closed then? |
@alicejgibbons , I tested it again with the dapr 1.14.4 and dotnet-sdk 1.14.0. It works for me now when calling the dapr endpoint via http directly. Also setting the Content-Type and datacontenttype via the metadata parameter doesn't appear to have an impact. |
@fabistb public async Task ChangeState(OutboxDto body)
{
var metadata = new Dictionary<string, string>
{
{ "contentType", "application/json" }, // Content type of the StateTransactionRequest
{ "datacontenttype", "application/json" } // Content type of the `data` field in cloudevent
};
await _daprClient.ExecuteStateTransactionAsync("outboxstatestore", new[]
{
new StateTransactionRequest(
body.Key,
ObjectToJsonByteArray(body),
StateOperationType.Upsert,
metadata: metadata // <- attach metadata
)
});
} The output was:
Then, I was able to successfully use The output was:
Please try the same and update if this helps. |
@antontroshin thanks! Unfortunately I think I think I managed to stumble in the next issue. In my example the controller method exceptions any kind of object. [HttpPost("outbox-topic")]
[Topic("messagebus", "outbox-topic")]
public async Task<IActionResult> ProcessStateInformation([FromBody] object message)
{
_logger.LogInformation(message.ToString());
return Ok();
} That is for debug purposes fine but in the running scenario it should accept the [HttpPost("outbox-topic")]
[Topic("messagebus", "outbox-topic")]
public async Task<IActionResult> ProcessStateInformation([FromBody] OutboxDto message)
{
_logger.LogInformation(message.ToString());
return Ok();
} If I change it like that it unfortunately fails with the following error.
The error doesn't make that much sense for me because the neither the DTO nor the request has a When I change the expected typ back If i now send the same string like the sdk generates directly to the Controller, I receive the same error as above. ### Post directly to pubsub endpoint
POST http://localhost:5070/api/v1.0/outbox/outbox-topic
Content-Type: application/json
"{"Key":"person1","FirstName":"Max","LastName":"Mustermann","Age":40}"
|
@fabistb This was fixed in the PR dapr/dapr#8062 opened following this issue and will be released in 1.14.5. |
@antontroshin great! |
Expected Behavior
A published pub/sub message by the outbox pattern be able to be consumed using the standard dotnet sdk setup.
Also the message published by the sdk should have a similar format than the message published by the dapr api itself.
Actual Behavior
The message published by using the sdk and an the api can't be consumed by the application using the
app.UseCloudEvents()
middleware which returns a 415.The message published als looks different depending on the utilization of the Dapr API or the dotnet sdk.
dotnet sdk:
dapr api:
Steps to Reproduce the Problem
Small example app:
https://github.com/fabistb/vis-dapr/tree/feature/53-add-outbox-pattern-example/Main#outbox-pattern
Affected versions
Initially tested with dotnet sdk 1.13.1.
@alicejgibbons also tested with 1.14.0-rc02 and confirms that the issue still persists.
Release Note
RELEASE NOTE:
FIX: Outbox pattern for dotnet sdk
The text was updated successfully, but these errors were encountered: