-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow sending message data as a string, not just as an array #46
Comments
Here is our current implementation of sending messages in chunks in case anyone is interested. |
@shantamg ably allows you to send message size bigger than 64k. Currently, it depends on your account type. Seems, 64k is default for PAYG account. You might like to check with support if limit can be increased. WDYT? |
Yes, the docs do say that it can be increased to 256k for "Committed Use". I suppose I could reach out to support and see what that entails and if there is much of a cost. For us, we are nowhere near exceeding our message count limit. I believe there are others who would rather send more messages than upgrade their plan for the sake of an increased message size limit. |
Since |
While it's true You can see resulting payload to be bloated because by default ably-sdks use If you still want to send payload as
So, while broadcasting, you should be able to send message data as string! |
Oh interesting! But hang on, I don't understand how that helps.
I am sending an array of data regardless so it's going to be encoded as json regardless, right? The only reason I wanted to send the data as a string, which you can see is possible in the next few lines, is because if I know my message is going to need to be split up, I need to encode it and chunk it, and that So to be clear, I usually send data as an array (and it's clear that it gets serialized into a json string by Thanks again for your interest in this question. I do agree that it may not be worth trying to get |
We want to be able to send data as a string
Since we are using laravel's event facade, we are limited to the payload being an array. Looking at the getPayloadFromEvent function, it's clear that
broadcastWith()
must return an array, because it's callingarray_merge
on the payload.Our use case
The reason we would like to send data as a string, which the ably-php library supports, is because we want to send a json-encoded string without it being bloated by double encoding.
This all started because we had some messages that were over the 64k limit. When I reached out to Ably support, it was suggested that we chunk the data, send it as multiple messages, and then put it together on the client side. That worked great until I realized that each chunk of serialized data was around 10k bigger after being serialized again as a part of the payload (which included a UUID to group the chunks, the total number of chunks, and the current chunk index).
So the idea I had was to reserve a fixed number of characters at the beginning for the metadata and then just send the whole thing as a concatenated string. Then I realized the limitation of laravel events and that became a dead end.
Our current solution
I have a solution that involves taking each chunk, calling
json_encode
on it to determine how many bytes over my max chunk size it becomes, and then reducing the chunk by that amount. It works, and is fast, but it's a shame that we have to sacrifice that message size for the double encoding.Any ideas? Could we extend laravel to support sending strings? Or just bypass the laravel event facade? That would also be a shame because our unit tests use
Event::assertDispatched
.┆Issue is synchronized with this Jira Task by Unito
The text was updated successfully, but these errors were encountered: