{"action":"created","issue":{"url":"https://api.github.com/repos/SimpleBus/MessageBus/issues/15","labels_url":"https://api.github.com/repos/SimpleBus/MessageBus/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/SimpleBus/MessageBus/issues/15/comments","events_url":"https://api.github.com/repos/SimpleBus/MessageBus/issues/15/events","html_url":"https://github.com/SimpleBus/MessageBus/issues/15","id":54879858,"number":15,"title":"How to serialize a Message to be published in a message queue?","user":{"login":"josecelano","id":58816,"avatar_url":"https://avatars.githubusercontent.com/u/58816?v=3","gravatar_id":"","url":"https://api.github.com/users/josecelano","html_url":"https://github.com/josecelano","followers_url":"https://api.github.com/users/josecelano/followers","following_url":"https://api.github.com/users/josecelano/following{/other_user}","gists_url":"https://api.github.com/users/josecelano/gists{/gist_id}","starred_url":"https://api.github.com/users/josecelano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josecelano/subscriptions","organizations_url":"https://api.github.com/users/josecelano/orgs","repos_url":"https://api.github.com/users/josecelano/repos","events_url":"https://api.github.com/users/josecelano/events{/privacy}","received_events_url":"https://api.github.com/users/josecelano/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/SimpleBus/MessageBus/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-01-20T12:57:33Z","updated_at":"2015-01-21T21:12:22Z","closed_at":null,"body":"I am using MessageBusMiddleware to send some kind of messages (those that implement interface IsHandledAsynchronously) to an ActiveMQ message queue. I want to store the Message in the queue message body (I am using stomp protocol).\r\n\r\nI have also written a Symfony command to susbcribe to messages from that queue.\r\n\r\nI need a way to serialize/deserialize the Message in the Stomp message body.\r\n\r\nI think I could encode the message in json format. My question is:\r\n\r\nWhere can I put the logic to get a json view from a Message?\r\n\r\nI need this:\r\n\r\n````\r\nclass UserWasRegisteredEvent implements Message, IsHandledAsynchronously\r\n{\r\n    /**\r\n     * @var integer\r\n     */\r\n    private $userId;\r\n\r\n    /**\r\n     * @param integer $userId\r\n     */\r\n    public function __construct($userId)\r\n    {\r\n        $this->userId = $userId;\r\n    }\r\n\r\n    /**\r\n     * @return string\r\n     */\r\n    public function getUserId()\r\n    {\r\n        return $this->userId;\r\n    }\r\n}\r\n````\r\n\r\nto be converted to this:\r\n\r\n````\r\n{\r\n  \"type\": \"Message\",\r\n  \"class\": \"UserWasRegisteredEvent \",\r\n  \"attributes\": {\r\n    \"user_id\": 5N1J32eZvKYlo2CqJ0wc8p5\",\r\n  }\r\n}\r\n````\r\n\r\nI suppose I need some metadata fields to hydrate a new Message instance from json  and even some kind of Message factory.\r\n\r\nMy goal is to pull Messages from queue, create again the Message and publish it in the EventBus, but this time without IsHandledAsynchronously interface (or not?).\r\n\r\nAnother question, how can avoit the Command/Event to be handled twice? If the Message is published in both the standard bus and the middleware bus. In the Message handler the only info I have is the Message. If I don't want to check the instance interface I have to have two different messages: UserWasRegisteredEvent and UserWasRegisteredAsynEvent .\r\n"},"comment":{"url":"https://api.github.com/repos/SimpleBus/MessageBus/issues/comments/70922603","html_url":"https://github.com/SimpleBus/MessageBus/issues/15#issuecomment-70922603","issue_url":"https://api.github.com/repos/SimpleBus/MessageBus/issues/15","id":70922603,"user":{"login":"josecelano","id":58816,"avatar_url":"https://avatars.githubusercontent.com/u/58816?v=3","gravatar_id":"","url":"https://api.github.com/users/josecelano","html_url":"https://github.com/josecelano","followers_url":"https://api.github.com/users/josecelano/followers","following_url":"https://api.github.com/users/josecelano/following{/other_user}","gists_url":"https://api.github.com/users/josecelano/gists{/gist_id}","starred_url":"https://api.github.com/users/josecelano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josecelano/subscriptions","organizations_url":"https://api.github.com/users/josecelano/orgs","repos_url":"https://api.github.com/users/josecelano/repos","events_url":"https://api.github.com/users/josecelano/events{/privacy}","received_events_url":"https://api.github.com/users/josecelano/received_events","type":"User","site_admin":false},"created_at":"2015-01-21T21:12:22Z","updated_at":"2015-01-21T21:12:22Z","body":"OK. Thanks. I will try to add that missing piece. I think finally I will create an AsynBus bundle with second command/event buses to execute command handlers and event subscribers asynchronously.\r\nI have founf some bundles which do that but I think this is the cleaner solution I have found until now (fomr the DDD point of view) to dispatch events asyncrousouly with Symfony.\r\n\r\nRegarding using your name in namespaces, first I tought to do a DDD sample project only to test simple-bus, that´s why it is your name. Later I thought to use the sample project to test some other concepts I want to test. I think I can keep your name for all code related to simple-bus and create new vendor folder for each new library/concept I want to test. In fact you are the vendor ;-)"}}