Add a header property in message event

Hi
in my messaging before publish event handler i want to add a property in the header of the message.
how can i do that?

Hi @mohammad_altoiher

If you want to add the header through the SDK, you can use PublishOptions. Here is the sample code for Android:

Map<String, String> headers = new HashMap<>();
headers.put("headerName", "headerValue");
PublishOptions publishOptions = new PublishOptions();
publishOptions.setHeaders(headers);
Backendless.Messaging.publish((Object) "My message", publishOptions);

Best Regards,
Maksym

I want to add the header property in the “beforePublish” event handler.
im doing some calculations in the event and i want to pass that to the subscribed users

Sorry, my mistake.
You can add the header to the PublishOptions in your event handler too. The beforePublish method receives the PublishOptions, so you can use the same code above.

Best Regards,
Maksym

im using codeless event.
i created a variable and named it PublishOptions. but that didn’t work.

Hello,

This is how the PublishOptions should be structured:
Codeless - BL - ConsoleDemo - Backendless 2020-06-02 08-58-57
Notice there is headers property, which should contain object containing headers/values.

Regards,
Mark

Hi, @mohammad_altoiher, try this

i tried it and the subscriber is not getting the the new property

Untitled

Could you check the contents of Request Publish Options after the property is set and before the event handler is done? This can be done using the print block and then checking in the real-time logging window when the API is executed.

it does have it
headers: { Request_id: 'request', ToUser: 'AAFCD463-3BF0-B20C-FF3B-C47584300000', FromUser: 'AAFCD463-3BF0-B20C-FF3B-C47584300000', ggg: '33' }

Thanks. Do you use real-time messaging to subscribe to the channel to receive messages or retrieve them using the REST endpoint?

i use the JS SDK to subscribe to the channel

Hi @mohammad_altoiher,

Internal ticket was created: BKNDLSS-21797.
We’ll let you know about solution.

Best regards,
Yevgen

@Yevgen_Baz
Any solution yet? my work is depended on it.

Hello @mohammad_altoiher,

the BKNDLSS-21797 ticket status is “Waiting for test”. We’ll notify you here as soon at it will be completed.

Regards,
Olha

Hi @mohammad_altoiher,

We’ve released the new version of Backendless. Please, could you be so kind to confirm that the issue disappears?

Best regards,
Yevgen

1 Like

i can add the header property but i get this when i want to return a the “created” column.


is this normal?

converting it to string first was the solution.