-
Notifications
You must be signed in to change notification settings - Fork 20
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
Why message body is of type string? #27
Comments
You should serialize it, for example into json or xml. There is no way you can send a php object as is. |
But it will be serialized twicely to send it via transport (redis, kafka, rabbitmq) - first time message body to string and second time message with serialized body into string. I think this is unnecessary overhead. |
I also don't see why to restrict body to
I guess this is not true. The Using There is no problem with ommiting return typehint of |
Why double? Your code encodes a data to JSON so it becomes a string, then send it as the message body. In turn, on a consumer side, you get a string which your cod decode to your data structure. The idea behind this decision is to keep encoding\decoding logic out of the scope of the Queue Interop. |
@makasim thank you for the prompt answer.
Because when you call $body = [
'foo' => 'bar',
];
$message = [
'body' => json_encode($body),
];
var_dump(json_encode($message)); // => string(28) "{"body":"{\"foo\":\"bar\"}"}" Ommiting |
Most of the transports accept only a string. What should those transport do if something else given? It would force us to introduce a kind of encoding\decoding interfaces so they can transform that data to a string. The other way is to throw an exception which is not interoperable (some transports would work but others dont) |
It is hard to tell without wide domain knowledge. Can you, please, give me an example of transport where you can use only |
@makasim I have looked through the I can create fork for this repo and fork for enqueue, that will use it. Just as proof of concept. Will you consider to review them and continue discussion? Thank you in advance. |
I've given it another thought and now I tend to agree with you. The issue is clearly present. Sure I'll review it! Thank you all for your effort. |
Hello guys e.g.
http://sandbox.onlinephpfunctions.com/code/61f3dd92697b40db568bbbd818959e9e493d57ae suggestion would be to remove |
waoooooo 14days and still no response :D |
Why message body is of type string https://github.com/queue-interop/queue-interop/blob/master/src/Message.php#L19? How can I send objects inside of message body? I need to double encode it? It is weird.
Java specification definitily says that body can be an object, a stream and so on https://docs.oracle.com/javaee/7/api/javax/jms/Message.html
The text was updated successfully, but these errors were encountered: