{"action":"created","issue":{"url":"https://api.github.com/repos/bennidi/mbassador/issues/122","labels_url":"https://api.github.com/repos/bennidi/mbassador/issues/122/labels{/name}","comments_url":"https://api.github.com/repos/bennidi/mbassador/issues/122/comments","events_url":"https://api.github.com/repos/bennidi/mbassador/issues/122/events","html_url":"https://github.com/bennidi/mbassador/issues/122","id":97622181,"number":122,"title":"Add pause/resume feature to MBassador","user":{"login":"bgroenks96","id":841306,"avatar_url":"https://avatars.githubusercontent.com/u/841306?v=3","gravatar_id":"","url":"https://api.github.com/users/bgroenks96","html_url":"https://github.com/bgroenks96","followers_url":"https://api.github.com/users/bgroenks96/followers","following_url":"https://api.github.com/users/bgroenks96/following{/other_user}","gists_url":"https://api.github.com/users/bgroenks96/gists{/gist_id}","starred_url":"https://api.github.com/users/bgroenks96/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bgroenks96/subscriptions","organizations_url":"https://api.github.com/users/bgroenks96/orgs","repos_url":"https://api.github.com/users/bgroenks96/repos","events_url":"https://api.github.com/users/bgroenks96/events{/privacy}","received_events_url":"https://api.github.com/users/bgroenks96/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-07-28T05:52:01Z","updated_at":"2015-10-30T09:40:12Z","closed_at":null,"body":"Hi,\r\nI've been working on a pull request to add a 'pause' and 'resume' feature to the message bus. Here are the methods from the new interface 'PubSubPauseSupport' with Javadoc comments to explain the concept:\r\n\r\n    /**\r\n     * Pauses event publishing. All messages submitted via {@link #publish(Object)} will be stored in a queue until\r\n     * {@link #resume()} is called. Any subsequent calls to this method before a call to {@link #resume()} will have no\r\n     * effect.\r\n     */\r\n    void pause();\r\n\r\n    /**\r\n     * Resumes event publishing. All messages enqueued since the first call to {@link #pause()} will be subsequently\r\n     * flushed and published in the order that they arrived. Does nothing if the runtime is not currently in a paused\r\n     * state from a call to {@link #pause()}.\r\n     */\r\n    void resume();\r\n\r\n    /**\r\n     * @return true if this PubSubPauseSupport is currently paused, false otherwise.\r\n     */\r\n    boolean isPaused();\r\n\r\nThis is especially useful in event-based applications that go through \"transitions\" i.e. a short period of time in which no Handler is able to receive events, yet it is problematic for inbound events to be completely lost. Being able to 'pause' the event publishing, queueing published events until it is resumed, solves this problem. There shouldn't be any performance cost on normal operation either.\r\n\r\nThe only thing that's tripping me up a bit is how to support `publishAsync` calls? Should `AbstractSyncAsyncMessageBus` keep another queue separate from the normal `BlockingQueue` or should that be the implementation's job?\r\n\r\nI would appreciate any feedback, and let me know if you want me to go ahead an push the pull request so you can see the rest of the changes."},"comment":{"url":"https://api.github.com/repos/bennidi/mbassador/issues/comments/152473829","html_url":"https://github.com/bennidi/mbassador/issues/122#issuecomment-152473829","issue_url":"https://api.github.com/repos/bennidi/mbassador/issues/122","id":152473829,"user":{"login":"bennidi","id":1842420,"avatar_url":"https://avatars.githubusercontent.com/u/1842420?v=3","gravatar_id":"","url":"https://api.github.com/users/bennidi","html_url":"https://github.com/bennidi","followers_url":"https://api.github.com/users/bennidi/followers","following_url":"https://api.github.com/users/bennidi/following{/other_user}","gists_url":"https://api.github.com/users/bennidi/gists{/gist_id}","starred_url":"https://api.github.com/users/bennidi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bennidi/subscriptions","organizations_url":"https://api.github.com/users/bennidi/orgs","repos_url":"https://api.github.com/users/bennidi/repos","events_url":"https://api.github.com/users/bennidi/events{/privacy}","received_events_url":"https://api.github.com/users/bennidi/received_events","type":"User","site_admin":false},"created_at":"2015-10-30T09:40:12Z","updated_at":"2015-10-30T09:40:12Z","body":"I would suggest you have a look at the mbassador-spring repository. The entire extension is based on a decorator like pattern. Instead of extending the core, the transactional bus wraps the sync-async bus, adds additional methods and delegates existing ones (adding extra code where necessary). I would advice you to take the same approach. In your method delegates to publish / publishAsync you just check for the AtomicBoolean and either route messages to your intermediate queue or to the underlying bus' method. Whenever resume is triggered you drain the queue (until paused again or queue is empty). Depending on your usecase you might need separate queues for sync and async publication. But maybe you can go with one and drain its content just into the async queue of Mbassador.\r\n\r\nHope I made myself clear."}}