Publish Order Events and Receive a Filtered Event Stream
Publish Order Events
You can use any REST API tool to publish order events. Because you already set up Postman to create the channel and channel member, continue to use Postman to publish events with REST API. You use the Composite resource to publish multiple platform event messages in one request.
The platform events you publish have this data.
Event | Order_Number__c | City__c | Amount__c |
---|---|---|---|
First event | 99 | San Francisco | 5205 |
Second event | 100 | San Francisco | 120 |
Third event | 101 | New York | 65 |
- In your fork of the Salesforce Platform APIs collection, expand Event Platform > Publish Platform Events, and click Publish multiple events.
- Click Body and ensure that raw and JSON options are selected.
- Replace the body with this JSON body. The JSON body contains three requests, each is for publishing one platform event message.
{ "allOrNone": true, "compositeRequest": [ { "method": "POST", "url": "/services/data/v58.0/sobjects/Order_Event__e", "referenceId": "event1", "body": { "Order_Number__c" : "99", "City__c" : "San Francisco", "Amount__c" : 5205 } }, { "method": "POST", "url": "/services/data/v58.0/sobjects/Order_Event__e", "referenceId": "event2", "body": { "Order_Number__c" : "100", "City__c" : "San Francisco", "Amount__c" : 120 } }, { "method": "POST", "url": "/services/data/v58.0/sobjects/Order_Event__e", "referenceId": "event3", "body": { "Order_Number__c" : "101", "City__c" : "New York", "Amount__c" : 65 } } ] }
- Click Send.
- Verify that the response status is 200 OK.
- The response contains the responses for the three platform event messages published, which looks something like this.
{ "compositeResponse": [ { "body": { "id": "e00xx0000000001AAA", "success": true, "errors": [ { "statusCode": "OPERATION_ENQUEUED", "message": "52e6cb5e-a800-4751-8ec2-3a8402def680", "fields": [] } ] }, "httpHeaders": { "Location": "/services/data/v58.0/sobjects/Order_Event__e/e00xx0000000001AAA" }, "httpStatusCode": 201, "referenceId": "event1" }, { "body": { "id": "e00xx0000000002AAA", "success": true, "errors": [ { "statusCode": "OPERATION_ENQUEUED", "message": "8a8e04ef-cdd2-4cde-91a9-8a17725a6c15", "fields": [] } ] }, "httpHeaders": { "Location": "/services/data/v58.0/sobjects/Order_Event__e/e00xx0000000002AAA" }, "httpStatusCode": 201, "referenceId": "event2" }, { "body": { "id": "e00xx0000000003AAA", "success": true, "errors": [ { "statusCode": "OPERATION_ENQUEUED", "message": "1e6299a5-487e-4dc7-8022-c4044a15c413", "fields": [] } ] }, "httpHeaders": { "Location": "/services/data/v58.0/sobjects/Order_Event__e/e00xx0000000003AAA" }, "httpStatusCode": 201, "referenceId": "event3" } ] }
Verify the Filtered Event Stream
After publishing the three platform event messages, the Order_Filtered_Channel__chn receives only one event message because it is the only one that matches the filter expression. As a refresher the filter expression is:
City__c='San Francisco' AND Amount__c<1000
The first event message doesn’t match the filter because it contains an Amount value greater than 1,000. The second event message matches the filter. Finally, the third event message doesn’t match the filter because the city is not San Francisco. Switch back to the Streaming Monitor tab to verify the event message is delivered to the Order_Filtered_Channel__chn
channel.
- In the Streaming Monitor app, verify one event message is displayed as a dot.
- To view the event message, click the dot. Verify that the event message contains these fields, in addition to system fields.
"Order_Number__c" : "100"
"City__c" : "San Francisco"
"Amount__c" : 120
You now know how to create custom channels and add filter expressions! Yay! To deepen your knowledge of stream filtering, check out Filter Your Stream of Platform Events with Custom Channels in the Platform Events Developer Guide.
Congratulations! You've verified receiving events by subscribing to a filtered channel. We won’t check any of your setup. Click Verify Step to complete this unit and earn your badge.
Resources