Comments (3)
Given your example here :
var createdEvent = new SessionCreated();
new CloudEvent<SessionCreated>(createdEvent) { Type = "session-created" };
metadata = new Dictionary<string, string);
metadata.Add("cloudevent.id", createdEvent.Id);
await client.PublishEventAsync("messagebus", "Session", cloudEvent, metadata);
You could create your own CloudEvent
(based on this ) and add an Id
field, then you could do something like this :
new CloudEvent<SessionCreated>(createdEvent) { Type = "session-created", Id = createdEvent.Id };
My understanding (which could be wrong) is that when you specify a CloudEvent
object, dapr will treat the model as-is, and won't attempt to interfere/augment it with other CE fields, (due to the content being set like this) So I think your metadata overrides are being ignored in this instance.
FWIW I can successfully override ce properties with this code, using redis :
request
is just a normal serializable POCO (not a CloudEvent)
var metadata = new Dictionary<string, string>();
metadata.Add("cloudevent.id", "123");
metadata.Add("cloudevent.type", "123");
metadata.Add("cloudevent.source", "123");
await daprClient.PublishEventAsync<StartWorkflowRequest>("kafka-pubsub", "workflowTopic", request, metadata, cts.Token);
this results in the following message body :
{
"data": {
...
},
"datacontenttype": "application/json",
"id": "123",
"pubsubname": "redis-pubsub",
"source": "123",
"specversion": "1.0",
"time": "2023-10-09T20:28:49Z",
"topic": "workflowTopic",
"traceid": "00-1c99e29b6f293df1836e945a1af06ffb-f4e20d12e31faa67-00",
"traceparent": "00-1c99e29b6f293df1836e945a1af06ffb-f4e20d12e31faa67-00",
"tracestate": "",
"type": "123"
}
from dotnet-sdk.
A better answer is just to derive a new class which extends CloudEvent
. Add any properties you require, CE or otherwise.
I.e. to include the ce field id
you can just do this :
public class CloudEvent2<TData> : Dapr.CloudEvent<TData>
{
public CloudEvent2(TData data) : base(data)
{
}
[JsonPropertyName("id")]
public string Id { get; init; }
}
var ce = new CloudEvent2<StartWorkflowRequest>(request) {
Id = "wf-" + Guid.NewGuid().ToString(),
Source = new Uri("/cloudevents/spec/pull/123"),
Type = "my-type" };
await daprClient.PublishEventAsync<CloudEvent2<StartWorkflowRequest>>("redis-pubsub", "workflowTopic", ce, cts.Token);
which generates the following message body in pubsub
{
"data": {
"failOnTimeout": false,
"id": "0-30"
},
"datacontenttype": "application/json",
"id": "wf-6d632d55-5ddd-4c8e-be01-fb3c98e7abc5",
"pubsubname": "redis-pubsub",
"source": "/cloudevents/spec/pull/123",
"specversion": "1.0",
"subject": null,
"time": "2023-10-11T12:01:58Z",
"topic": "workflowTopic",
"traceid": "00-d38ec30dbe1a3e7ad13430344cf62416-7996fe9086ffa58d-00",
"traceparent": "00-d38ec30dbe1a3e7ad13430344cf62416-7996fe9086ffa58d-00",
"tracestate": "",
"type": "my-type"
}
from dotnet-sdk.
I will give that a try. So the crux of the problem is when you pass a CloudEvent
or derived class to PublishEventAsync
the metadata you pass it will be ignored. This behavior should probably be documented somewhere. The documentation leads me to think otherwise the way it currently reads.
from dotnet-sdk.
Related Issues (20)
- [Proposal] Deprecate .NET 6/7 support in favor of .NET 8 in fall release HOT 3
- Token returned by QueryStateAsync() does not work for subsequent queries HOT 2
- Actor proxy reuses HTTP request when performing a retry to call an actor HOT 1
- SaveBulkStateAsync() throws context deadline exceeded exception HOT 3
- How to use ExecuteStateTransactionAsync() HOT 3
- It is not possible to read headers sent from a RabbitMQ message HOT 3
- Unable to use EventHub or Service Bus Dapr Component HOT 1
- Update the holopin.yml to use the sdk badge HOT 2
- Unable to stream using HTTP service invocation HOT 1
- Add option to handle 'dead letters' by sending them to a dead letter queue rather than a dead leter topic HOT 2
- intermittent exceptions from WorkflowLoggingService
- AddDaprSecretStore() fails on Kubernetes HOT 1
- Regarding custom middleware to setup in the pipeline and how to create
- Regarding custom middleware to setup in the pipeline and how to create
- PublishEventAsync Blocking When Delivering Locally? HOT 7
- Cryptography Support Enhancements
- SaveBulkStateAsync does not respect DAPR_API_TOKEN
- Standardize README with shield badges HOT 8
- Dead letter subscription not working with pub sub having consumer ID specified in metadata
- Allow access to injected services during DI registration of DaprClient HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dotnet-sdk.