How to set PartitionKey property from stream analytics on the output message to service bus? - azure-stream-analytics

I have following setup:
Event hub
Service bus topic with a single subscription that accepts all messages from the topic (for my POC)
Above service bus subscription is setup with sessions enabled
Stream analytics (SA) job that moves the events from event hub (the input) into service bus topic (the output). Here is my SA query:
SELECT *, LOWER(source) as Partner
INTO [sb-output]
FROM [test-input]
The above job also sets the partition key for service bus. Used following json in the System Properties of [sb-output] based on the documentation at https://learn.microsoft.com/en-us/azure/stream-analytics/service-bus-topics-output#custom-metadata-properties-for-output:
{ "PartitionKey" : "Partner" }
What I did:
Sent an event to event hub without partition key. This was successful.
{
"specversion": "1.0",
"id": "c8c4faad-9f53-4e43-95ca-c318d673660a",
"type": "CustomerChanged",
"time": "2020-09-09T22:25:40.0148301Z",
"source": "ABCD",
"subject": "system-1",
"datacontenttype": "application/json",
"dataschema": "1.0",
"data": {
"customerNumber": "7879875212123",
"firstName": "John",
"lastName" : "Kennedy"
}
}
The SA successfully moved the event from event hub to service bus.
The service bus subscription succcessfully received the message as shown below:
{
"specversion": "1.0",
"id": "c8c4faad-9f53-4e43-95ca-c318d673660a",
"type": "CustomerChanged",
"time": "2020-09-09T23:22:13.3647825Z",
"source": "ABCD",
"subject": "system-1",
"datacontenttype": "application/json",
"dataschema": "1.0",
"data": {
"customerNumber": "7879875212123",
"firstName": "John",
"lastName": "Kennedy"
},
"EventProcessedUtcTime": "2020-09-09T23:22:14.3776603Z",
"PartitionId": 0,
"EventEnqueuedUtcTime": "2020-09-09T23:22:14.3080000Z",
"Partner": "abcd"
}
As can be seen, the property Partner is at the end of the message.
However the Service Bus Explorer tool shows me that the PartitionKey property has not been set to "abcd" but to some other random string.
Troubleshooting:
To make sure that I can send a message to service bus topic with a specific PartitionKey key, I wrote a sample code that submits the message to service bus topic by explicitly setting the session id property on the message. The service bus explorer showed me that both SessionId as well as PartitionKey properties are set to the correct value.
In ASA output configuration, tried to set following system properties json. Neither worked.
{ "SessionId" : "Partner" }
{ "PartitionKey" : "Partner", "SessionId" : "Partner" }
In ASA output configuration, tried setting both Property Columns (to Partner) as well as System Property Columns (to { "PartitionKey" : "Partner" }). That did not work.
Question:
What am I doing wrong with ASA output configuration that is circumventing the propagation of PartitionKey value from my custom field to service bus message?
Also is there a reason why the System Property Columns does not show the json text that I entered after saving?

Sharing the answer as per the comment by the original poster:
Currently, Microsoft is working on a fix.
Until then, you can use the suggested work around: { "PartitionKey" : "Partner", "SessionId" : "Partner", "Label": "Partner" } in system properties.

Related

Shopware 6 Admin Api - Updating existing record through patch method. Not working

shopware 6 admin api patch - why it's failing? I get error "Only single write operations are supported"
Following is api for rule-condition entity in the database, I update it with Id.
For same api get method is working!
url: api/rule-condition/dbb0d904c7c14860a9a94cf26b94eca6
method: patch
json body
[
{
"op": "replace",
"path": "/data/attributes/value/email",
"value": "test#gmail.com"
}
]
response:
{
"errors": [
{
"code": "0",
"status": "400",
"title": "Bad Request",
"detail": "Only single write operations are supported. Please send the entities one by one or use the /sync api endpoint.",
.......
I also tried changing json body to following
{
"data": {
"attributes": {
"value": {
"email": "test#gmail.com"
}
}
} }
Still it's not updating. Can somebody check and let me know what am i missing?
Documentation I followed:
https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyMzA4NTQ5-writing-entities
This website has all apis and example methods. https://swagger.docs.fos.gg/,
rule-condition entity can also be found there.
Btw : I used postman for testing api
You're passing an array of objects in the request body, suggesting you want to update multiple records, but the endpoint only supports updating a single record. The correct payload in your case should look like this:
{
"value": {
"operator": "=",
"email": "test#gmail.com"
}
}
Notice that value is a json field and not only includes a single value. The exact content and the names of the properties of value depend on the type of condition used and usually it also includes the operator used in the condition.

Enrich device life cycle events Azure IoT Hub

I need to enrich the device life cycle events[Created, Deleted, Connected, Disconnected] received on Event Grid.
The event flow in my solution is like below:-
Device send registration request to IoT Hub -> Event grid triggers device life cycle event -> Event grid routes device life cycle event to Event Hub.
Since my application i.e. consumer to Event hub only that is the reason I'm routing all events to Event Hub from Event Grid.
Now, I need to enrich the event received on Event hub. For example, the device connected event should look like below:
{
"body": [
{
"id": "58b1872d-1388-8043-dacc-6322ca65d2bf",
"topic": "SOME_TOPIC",
"subject": "devices/diablo-central-park-1",
"eventType": "Microsoft.Devices.DeviceConnected",
"data": {
"deviceConnectionStateEventInfo": {
"sequenceNumber": "SOME_SEQ_NUMBER"
},
"hubName": "IOT_HUBNAME",
"deviceId": "DEVICE_ID"
},
"dataVersion": "",
"metadataVersion": "1",
"eventTime": "2020-10-16T06:33:42.2418032Z"
}
],
"properties": {
"aeg-output-event-id": "SOME_ID",
"aeg-subscription-name": "SOME_NAME,
"aeg-delivery-count": "0",
"aeg-data-version": "",
"aeg-metadata-version": "1",
"aeg-event-type": "Notification",
"enrichedProperty": "enrichedValue"
},
"offset": "25769816448",
"sequenceNumber": 2197,
"enqueuedTimeUtc": "2020-10-16T06:33:49.321Z",
""systemProperties": {}
}
So, In above event JSON, I should get the enrichedProperty in the properties field. I have done message enrichment for twin change events, telemetry through Message routing(Enrich Messages)in IoT hub blade on the portal. But for device life cycle events I could not find a way.
This should work in a very similar manner. So you create an end point (e.g. a storage container), then create a route making sure you choose "Device Lifecycle Events" in the data source of the route. then go to "enrich messages" tab and add the name and value of the property that you want , making sure the correct end point is selected. Also make sure that the root is enabled and the route query is true. Now when you create or delete a device, your events will be captured and the enriched property will appear in the captured event properties.

Create Controller Service using Nifi API REST

I am trying to create a controller service using nifi api rest but I am blocked because when I try:
InvokeHTTP
POST
https://hostname/nifi-api/controller/controller-services
using this json
{
"revision": {
"version": 0
},
"disconnectedNodeAcknowledged": false,
"component": {
"name": "DMCS_try",
"type": "org.apache.nifi.distributed.cache.server.map.DistributedMapCacheServer",
"bundle": {
"group": "org.apache.nifi",
"artifact": "nifi-distributed-cache-services-nar",
"version": "1.9.0.3.4.1.1-4"
},
"state": "ENABLED",
"properties": {
"Port": "4555",
"Maximum Cache Entries": "10000",
"Eviction Strategy": null,
"Persistence Directory": null,
"SSL Context Service": null
}
}
}
I got this "error"
Node XXXXXXXXX is unable to fulfill this request due to: Unable to modify the controller. Contact the system administrator. Contact the system administrator.
Controller services can be created in two different places. One place is in the flow as part of a process group so they can be used by processors, the other place is at the controller level for use by reporting tasks.
The URL you specified is for creating a service at the controller level and therefore whatever identity you are using to authenticate as need permissions to modify the controller (WRITE on /controller). The error message is saying you don't have that permission.

How to post event with metadata to stream through HTTP API

I'm using EventStore and want to post a message (event) to it. I use the HTTP API for testing purposes. I've managed to post the event itself, with an event type specified, but I can't figure out how to specify metadata for my event. (and I must provide this metadata because my consuming application on the other side expects it).
This is what my HTTP request looks like:
Content-Type: application/json
ES-EventType: My.own.event.type
POST http://10.0.75.2:2113/web/index.html#/streams/foobar
{
"props": "andvalues"
}
Do I specify metadata in the body in through headers? I can't find much docs about this, only the official that doesn't mention it.
The documentation mentions the full schema for an event being written. It looks like this:
[
{
"eventId" : "string",
"eventType" : "string",
"data" : "object",
"metadata" : "object"
}
]
For example:
[
{
"eventId": "fbf4a1a1-b4a3-4dfe-a01f-ec52c34e16e4",
"eventType": "event-type",
"data": { "a": "1" },
"metadata": { "b": "2" }
}
]
Note that it's an array, and that you must pass content-type as application/vnd.eventstore.events+json
Check this page, scroll to Event Store Events Media Type.

Can we receive step data in the pub sub payload?

I can see in the payload JSON that the pubsub notification includes the events but is it also capable of sending the activity or sleep amounts (e.g steps or sleep minutes)?
No, the pubsub notification will only include the user and the list of events that took place. You can then use this information to query the APIs that pertain to those specific types of events.
For example, suppose you receive the following pubsub notification:
{
"notification_timestamp": "1372787949",
"events": [
{
"user_xid": "RGaCBFg9CsB83FsEcMY44A",
"event_xid": "EJpCkyAtwoO0XTdkYyuTNw",
"type": "move",
"action": "creation" ,
"timestamp": "1372787849"
},
{
"user_xid": "RGaCBFg9CsB83FsEcMY44A",
"event_xid": "blaHyAtwoO0XTdkYyuTNw",
"type": "sleep",
"action": "updation" ,
"timestamp": "1372787859"
}
],
"secret_hash": "e570b3071a0964f9e2e69d13nd9ba19535392aaa",
}
Then you know that a move event was created and that a sleep event was updated for the user specified by user_xid: RGaCBFg9CsB83FsEcMY44A
Use this user's xid to determine which previously saved access_token to send with your next API requests.
You can get the details for the move event by sending a request to the moves endpoint with the event_xid: EJpCkyAtwoO0XTdkYyuTNw:
GET https://jawbone.com/nudge/api/v.1.1/moves/EJpCkyAtwoO0XTdkYyuTNw
And yo ucan get the details for the sleep event by querying the sleeps endpoint with the event_xid: blaHyAtwoO0XTdkYyuTN:
GET https://jawbone.com/nudge/api/v.1.1/sleeps/blaHyAtwoO0XTdkYyuTN