{"id":18407698,"url":"https://github.com/maxikg/messenger-java","last_synced_at":"2025-10-30T09:43:03.067Z","repository":{"id":150295922,"uuid":"49004721","full_name":"maxikg/messenger-java","owner":"maxikg","description":"Not longer maintained. Have a look at https://github.com/CloudBans/barker if you're interested in.","archived":false,"fork":false,"pushed_at":"2016-01-04T21:57:09.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T21:39:05.641Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxikg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-04T15:14:46.000Z","updated_at":"2016-03-25T12:15:33.000Z","dependencies_parsed_at":"2023-04-17T16:00:38.813Z","dependency_job_id":null,"html_url":"https://github.com/maxikg/messenger-java","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/maxikg/messenger-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxikg%2Fmessenger-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxikg%2Fmessenger-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxikg%2Fmessenger-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxikg%2Fmessenger-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxikg","download_url":"https://codeload.github.com/maxikg/messenger-java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxikg%2Fmessenger-java/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260277502,"owners_count":22985102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T03:15:02.128Z","updated_at":"2025-10-30T09:42:57.997Z","avatar_url":"https://github.com/maxikg.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Messenger [![Build Status](https://travis-ci.org/maxikg/messenger-java.svg)](https://travis-ci.org/maxikg/messenger-java)\n\nMessenger is a routing library primary for AMQP but may be adoptable for other messaging systems. Messenger helps to\nrealize a communication between various instances and software.\n\nPossible use cases may be:\n\n * **Multiple Websocket servers:** Routes a message to the point on which a determined websocket is connected.\n * **Distributed Bukkit/BungeeCord:** Routes a message from Bukkit to a BungeeCord or another Bukkit instance on which\n   a player is connected. Of course also routing to servers by their names is possible.\n\nBy default an AMQP implementation is shipped with this library. Each endpoint generates a queue and ensures that the\nright exchange is available. Each subscription will bind the temporary queue to the exchange.\n\n## Features\n\n * Simple handle of AMQP binds/unbinds\n * Gson adapter for working with models instead of raw messages\n\n## Installation\n\nThe software is currently not deployed to any Maven repository. So you need to install it by hand:\n\n 1. Clone the repository: `git clone https://github.com/maxikg/messenger-java.git`\n 2. Change directory: `cd messenger-java`\n 3. Invoke maven: `mvn install`\n\nAfter a successful build the library is available in your local Maven repository:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ede.maxikg\u003c/groupId\u003e\n    \u003cartifactId\u003emessenger\u003c/artifactId\u003e\n    \u003cversion\u003e0.2.0-SNAPSHOT\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Example\n\nSince the default implementation uses the AMQP protocol there is a compatible message broker required. I highly\nrecommend [RabbitMQ](https://www.rabbitmq.com/).\n\nIf you're not sure which imports are used in the following code snippets, here's a list of them:\n\n```java\nimport com.rabbitmq.client.Connection;\nimport com.rabbitmq.client.ConnectionFactory;\nimport de.maxikg.messenger.AmqpMessenger;\nimport de.maxikg.messenger.queue.Queue;\nimport de.maxikg.messenger.queue.listener.QueueListener;\n```\n\nFirst of all we need a connection to the broker. In this case we connect to a Broker on localhost and use the virtual\nhost `test`. The virtual host must be present.\n\n```java\nConnectionFactory connectionFactory = new ConnectionFactory();\nconnectionFactory.setUri(\"amqp://localhost/test\");\n\nConnection connection = connectionFactory.newConnection();\n```\n\nNow we can construct a new `AmqpMessenger`. A `Messenger` is a helper object containing a `Publisher` for outgoing\nmessages and a `Queue` for incoming messages. Each Messenger is able to serve one namespace and will use one Channel.\n\n```java\nAmqpMessenger messenger = new AmqpMessenger(connection, \"messenger\", \"test\");\nmessenger.initialize();\n```\n\nAfter the messenger is initialized we're able to subscribe to messages and publish them. But first of all we're going\nto subscribe some targets and add a listener:\n\n```java\nQueue queue = messenger.getQueue();\nqueue.subscribe(\"test\");\nqueue.addListener(new QueueListener() {\n    @Override\n    public void onMessage(String namespace, String target, String type, byte[] message) {\n        System.out.println(new String(message));\n    }\n});\n```\n\nNow we can test it by publishing two messages:\n\n```java\nmessenger.getPublisher().publish(\"test\", null, \"Hello World!\".getBytes());\nmessenger.getPublisher().publish(\"something\", null, \"This shouldn't be displayed!\".getBytes());\n```\n\nThe console will display \"Hello World!\" since this is published to *test* what we've subscribed in the last step. But\nthe second message won't be displayed since it is published on something we've never subscribed. The unroutable message\nwill be just dropped.\n\n### Use Gson adapter\n\nIf you want to use model objects instead of raw messages you can use Google GSON and the build in adapter for it.\nPlease follow all above steps up to `messenger.initialize();` before you start with the Gson adapter. In the following\nexample we use different imports:\n\n```java\nimport com.rabbitmq.client.ConnectionFactory;\nimport de.maxikg.messenger.AmqpMessenger;\nimport de.maxikg.messenger.gson.AbstractObjectMessageListener;\nimport de.maxikg.messenger.gson.ObjectMessenger;\n```\n\nFurthermore we using a Model class named `Demo`:\n\n```java\npublic class Demo {\n\n    private final String test;\n    \n    public Demo(String test) {\n        this.test = test;\n    }\n    \n    public String getTest() {\n        return test;\n    }\n    \n    @Override\n    public void toString() {\n        return getClass().getSimpleName() + \"(test=\" + getTest() + \")\";\n    }\n}\n```\n\nIf your Messenger is ready you can start by constructing a `ObjectMessenger`:\n\n```java\nObjectMessenger objectMessenger = new ObjectMessenger(messenger);\n```\n\nThe ObjectMessenger is used to manage the Message-Object-Conversion. By default a objects class domain name is used for\nthe type argument but you can specify type aliases on the `TypeRegistry`. In this example we don't use this feature.\nWe directly registering a listener:\n\n```java\nmessenger.getQueue().subscribe(\"test\");\nobjectMessenger.getListenerRegistry().register(new AbstractObjectMessageListener\u003cDemo\u003e(Demo.class) {\n    @Override\n    public void onMessage(String namespace, String target, Demo object) {\n        System.out.println(object);\n    }\n});\n```\n\nAfter the listener is registered you can submit a `Demo` object:\n\n```java\nobjectMessenger.getPublisher().publish(\"test\", new Demo(\"Hello World\"));\n```\n\nThe console should display something like `Demo(test=Hello World)`.\n\n## ToDo\n\n * Correct reconnection handle\n * Add JavaDoc\n\n## License\n\nThis software is licensed under Apache License v2. A copy of this license is shipped within this repository in the\n[LICENSE.txt](/LICENSE.txt) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxikg%2Fmessenger-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxikg%2Fmessenger-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxikg%2Fmessenger-java/lists"}