Comments (21)
If the event holds a Message the notificationType
will be of type Message
and the ISubscriptionDelivery will be deserialized correctly as a https://github.com/commercetools/commercetools-dotnet-core-sdk-v2/blob/master/commercetools.Sdk/commercetools.Sdk.Api/Generated/Models/Subscriptions/IMessageDelivery.cs
See also
from commercetools-dotnet-core-sdk-v2.
Yes and it will be an instance of these classes:
But you also can pattern match on the Interfaces
from commercetools-dotnet-core-sdk-v2.
Released 2.1.1 with the fix. Should be available in some minutes
from commercetools-dotnet-core-sdk-v2.
Hi,
once you setup the subscriptions at commercetools. The platform will sent messages or events to your ServiceBus. If you configured it using the CloudEvents format you can deserialize the payload using any CloudEvents library for dotnet. If you have choosen platform format you should use the SDK Serializer to deserialize the payload to https://github.com/commercetools/commercetools-dotnet-core-sdk-v2/blob/master/commercetools.Sdk/commercetools.Sdk.Api/Generated/Models/Subscriptions/ISubscriptionDelivery.cs
More info about the delivery payload can be found here https://docs.commercetools.com/api/projects/subscriptions#delivery
from commercetools-dotnet-core-sdk-v2.
In case you only need the serializerservice you can use the UseCommercetoolsApiSerialization method:
And then the ServiceProvider to retrieve a SerializerService instance
from commercetools-dotnet-core-sdk-v2.
Thank you, any chance to have a sample using your tools (ie SDK Serializer) to consume events ? I'm not familiar with this approach
from commercetools-dotnet-core-sdk-v2.
Please see
to register the SerializationService to the ServiceProvider and
How to deserialize the payload
from commercetools-dotnet-core-sdk-v2.
Thank you for the sample/integration test.
I guess I misunderstood something, looking at the the "Resources/Messages/ResourceCreatedPayload.json" content and the ResourceCreatedDelivery/ResourceUpdatedDelivery/ResourceDeletedDelivery, the event doesn't transport data from the event itself (ie ECST), let's say a ProductCreatedMessage with its productProjection ?
Then is the recommandation to :
- trigger on event consumption, deserialize as ResourceCreatedDelivery/ResourceDeleteDelivery/ResourceUpdatedDelivery object
- detect wich entity is concerned by an action, then query it using the Messages Query HTTP API let's say using it's ID ?
- the returned object is strongly typed ? (ie ProductCreatedMessage)
Am I right ?
from commercetools-dotnet-core-sdk-v2.
If the event holds a Message the
notificationType
will be of typeMessage
...
I was missing this part, it's realy clear then. I guess we can apply pattern matching on
right, (once its deserialized) ?
from commercetools-dotnet-core-sdk-v2.
Ok ! I guess it will be easier to deal with it once we'll have events to play with on the Bus.
Thank you very much for your time and explanations. If further questions come to me, do I have to reach the another communication channel (Jira, support email ...) ? or Github issue is fine ?
from commercetools-dotnet-core-sdk-v2.
Questions regarding the SDK itself are fine to be asked at Github :)
from commercetools-dotnet-core-sdk-v2.
Thank you, I close the issue then. Have a good day
from commercetools-dotnet-core-sdk-v2.
@jenschude I'm sorry to bother you again, but I played a bit with the tests from the lib to have a better understanding of how does it works, this part is critical for our own integration, so I have few more questions :
Correct me if I'm wrong, but as I understood, in the following test :
you deserialize the raw string as a
List<ISubscriptionDelivery>
, doing so you get typed objects for ResourceCreatedDelivery/ResourceUpdatedDelivery/ResourceDeletedDelivery
(ie notificationType != "Message"
). But for the fourth message ("notificationType": "Message" and "type": "CustomerCreated"
) the object is typed as a MessageDelivery
, thus we can't access the strongly typed object (CustomerCreatedMessage
) unless we do an explicit deserialization as you do in the next test :On the other hand deserializing str payload as IMessage
(or as List<IMessage>
) allows to access strongly typed messages without any extra deserialization
But if any
notificationType != "Message"
is deserialized this way, the object is typed as a Message
, and we don't have the information about its type (ResourceCreatedDelivery/ResourceUpdatedDelivery/ResourceDeletedDelivery
).
Example with a mixed json ("notificationType": "Message" and "notificationType" != "Message"
)
-
Considering a raw string consumed from the bus, am I supposed to try both
ISubscriptionDelivery
andIMessage
deserializations to get my strongly typed event ? Or the subscribers to the bus expect to have filtered events coming in, then we can safely try to deserialize asISubscriptionDelivery
or asIMessage
only as we will always receive the same kind of events from a subscriber perspective ? -
In the second test when
How can you infer the T type ? Should we inspect the str payload itself ? Or is it for test purpose only and most of the time (always ?) we try to deserialize asIMessage
directly ? -
What is the typical scenario of events beeing produced lets say when a Product is created on commercetools?
Do we receive both"notificationType": "ResourceCreated"
message and"notificationType": "Message"
with"type": "ProductCreated"
message ?
Are there scenarii where we don't receive both ?
As we'll react to these events, especially with data synchronization operations in our downstreams we have to know if we can 'ignore'notificationType" != "Message"
for example, only dealing withnotificationType" : "Message"
or some use cases need to deal with both ? -
When the payload is not provided (
PayloadNotIncluded != null
), which API do we have to call to get it from a sync remote call ?
Again, thank you for your time
from commercetools-dotnet-core-sdk-v2.
Hi @jenschude
We plan to start the integration POC next week, we are currenlty following the 'Functional Training Session' (with Calvin and Michael).
Well do I need to switch to a more 'official' channel, as we bought an official licence ? Or is it part of the '.net SDK Training' that I should ask my questions ? Indeed we would like to avoid bad practices and follow your guidelines as much as possible, it'll save us time.
So if you've some time to deal with my questions, many thanks
from commercetools-dotnet-core-sdk-v2.
Oh man I now took a closer look and found a hole in the logic as the Message is not unmarshalled when using the MessageDelivery. Next week we can fix this and also extend the tests with some different use cases. Nevertheless the deserialization depends on the type of the Subscription and can be simplified if necessary
from commercetools-dotnet-core-sdk-v2.
Btw when using Azure you could also use the CloudEvents format instead of the platform format. Especially as Azure already comes with native CloudEvents support. The data
payload of the Event would then be the Message and you could use the SerializerService to deserialize it to the respective class instance
from commercetools-dotnet-core-sdk-v2.
Thank you for your feedback (and running PR).
Well with this fix, when do you try to deserizalize the Azure Service Bus raw string as ISubscriptionDelivery
rather than IMessage
? Should we inspect the raw string on some existing field to choose ?
We basically need the event carrying data that has been produced from the mutation in CT.
It's not clear to me in which case you use one rather than another
Thank you
from commercetools-dotnet-core-sdk-v2.
This is what the CloudEvent payload for a Message subscription would look like.
To my knowlegde there is a CloudEvent library available from Azure which could be used to deserialize this payload. The data field itself could then be mapped to the IMessage interface, as the delivery related fields are included in the cloud event itself.
{
"specversion": "1.0",
"id" : *any-uuid*,
"type" : "com.commercetools.product.message.ProductPublished",
"source" : "/<project-key>/products",
"subject" : "<product-id>",
"time" : *any-date-time*,
"sequence" : "3",
"sequencetype" : "Integer",
"dataref": "/<project-key>/messages/<msg-id>",
"data": {
"notificationType": "Message",
"projectKey": "<project-key>",
"version": 1,
"sequenceNumber": 3,
"resource": {
"typeId": "product",
"id": "<product-id>"
},
"resourceUserProvidedIdentifiers": {
"key": "subscription-product",
"slug": <product-slug>
},
"removedImageUrls": [],
"productProjection": {
"id": "<product-id>",
"version": 4,
"productType": {
"typeId": "product-type",
"id": "<product-type-id>"
},
"categories": [],
"categoryOrderHints": {},
"searchKeywords": {},
"hasStagedChanges": false,
"published": true
},
"resourceVersion": 4,
"type": "ProductPublished"
}
}
from commercetools-dotnet-core-sdk-v2.
Ok we'll try both approachs : raw string and CloudEvent messages and see what best suits our needs.
But both should produces the same deserialized object, doesn't it ?
from commercetools-dotnet-core-sdk-v2.
They should as the json structure is the same.
The nice thing about the CloudEvents format would be, that you could route the events in the Azure Event Grid natively.
from commercetools-dotnet-core-sdk-v2.
Yes, and it gives a formalism.
Well the 'auto routing' events is a great, but my final sink is Kafka :-/
from commercetools-dotnet-core-sdk-v2.
Related Issues (20)
- CentPrecisionMoney conversion mismatch HOT 1
- Quotes: quoteState missing from IQuote in commercetools.Sdk.Api.Models.Quotes HOT 3
- MessageSubscription: Breaking change from 5.1 to 5.2? HOT 1
- Question about Serialization/Deserialization of messages HOT 8
- Custom timeouts and retries on HTTP Client HOT 2
- Issue Creating Cart with Custom Line Item with Line-Item Custom Field HOT 1
- No Blazor WASM support HOT 4
- Product exists HEAD call support HOT 1
- Image upload always missing content type HOT 1
- OOTB models in SDK not serializing properly HOT 9
- How to create a HTTP Subscription with Extension Destination HOT 1
- Use ISerializerService in Dependency Injection Setup HOT 5
- Commercetool HTTP Client not working with Single-file deployment
- Fix Security Vulnerability with System.Text.Encodings.Web HOT 2
- Bypass 409 concurrentmodificationexception and overwrite the resource HOT 1
- LineItems is null but it should not be null. Schema can be outdated HOT 2
- Unable to Add header with IClient HOT 6
- ProductProjectionPagedQueryResponse is Generated with a long Offset while the query only accepts a int32 offset. HOT 2
- Filter categories by subtree HOT 1
- BadRequest On FailedLogin (Wrong username/password) HOT 4
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 commercetools-dotnet-core-sdk-v2.