{"id":13807363,"url":"https://github.com/saffron-technology/vertx-eventbusbridge","last_synced_at":"2025-05-14T00:31:15.893Z","repository":{"id":102761744,"uuid":"39237126","full_name":"saffron-technology/vertx-eventbusbridge","owner":"saffron-technology","description":"Event Bus bridge for Java applications interacting remotely with Vert.x ","archived":false,"fork":false,"pushed_at":"2018-11-15T23:29:39.000Z","size":24,"stargazers_count":18,"open_issues_count":5,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-18T23:52:48.874Z","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/saffron-technology.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-07-17T05:45:13.000Z","updated_at":"2024-05-04T16:17:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"6c4a2bab-42bd-471a-ad94-126b7f30fc51","html_url":"https://github.com/saffron-technology/vertx-eventbusbridge","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saffron-technology%2Fvertx-eventbusbridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saffron-technology%2Fvertx-eventbusbridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saffron-technology%2Fvertx-eventbusbridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saffron-technology%2Fvertx-eventbusbridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saffron-technology","download_url":"https://codeload.github.com/saffron-technology/vertx-eventbusbridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254046280,"owners_count":22005567,"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-08-04T01:01:24.649Z","updated_at":"2025-05-14T00:31:10.774Z","avatar_url":"https://github.com/saffron-technology.png","language":"Java","funding_links":[],"categories":["Vert.x Event Bus Clients","进程间通信"],"sub_categories":["WebService框架"],"readme":"# Eventbus-Bridge\n\nThis is an implementation of the event bus bridge that allows Java applications to send and receive event bus messages using the SockJS websocket sub-protocol.\nThe API mimics the one used in `vertxbus.js`.\nInternally, vert.x is used for websocket communication to the SockJS service that governs which event bus addresses are available.\n\n### Why would I use this? \n\nIf you would like to send or received messages on the Vert.x event bus using SockJS/websocket communication.\n\n## Usage\n\nEventBusBridge is the main class to use. Start with the connect method and take it from there.\n\n### Simple Example\n\nCall the static connect method with an URI and a connection handler.\n\nYou should not be using the EventBusBridge instance returned by connect before `isOpen` returns true.\nThe best way to guarantee this is to access the EvenBusBridge inside the connection handler.\n\nHere's an example that opens a connection to the Vert.x event bus via the SockJS service, registers a message handler and publishes a text message.\n\n```java\nEventBusBridge.connect(URI.create(\"http://localhost:8765/bridge\"), eb -\u003e {\n    eb.registerHandler(\"test\", msg -\u003e {\n         System.out.println(\"I gots a message:\" + msg);\n     });\n     eb.publish(\"test\", \"hello\");\n});\n```\n\nFor this example to work, a SockJS service needs to run on the server side that allows incoming and outgoing messages on the `test` address.\nHere's an example:\n\n```java\nvertx = Vertx.vertx();\nRouter router = Router.router(vertx);\n\n// events specific to THOPs are made available over the bridge\nSockJSHandler sockJSHandler = SockJSHandler.create(vertx);\nBridgeOptions options = new BridgeOptions();\noptions.addOutboundPermitted(new PermittedOptions().setAddress(\"test\"));\noptions.addInboundPermitted(new PermittedOptions().setAddress(\"test\"));\nsockJSHandler.bridge(options);\n\nrouter.route(\"/bridge/*\").handler(sockJSHandler);\nvertx.createHttpServer().requestHandler(router::accept).listen(8765, (res) -\u003e {\n    System.out.println(\"I'm here to serve\");\n});\n```\n\nRegistering handlers comes in two flavors `EventHandler` and `MessageHandler`.\n`EventHandler` in addition to the message payload also gives you access to the `EventBusBridge` instance which might be more convenient in some cases.\nHere's an example that shows the difference:\n\n```java\neb.registerHandler(\"test\", msg -\u003e { ... } );\neb.registerHandler(\"test\", (msg, eventBus) -\u003e { ... });\n```\n\n### Message payload\n\nWhile Vert.x supports arbitrary message types on the event bus, this bridge only supports plain text and JsonObjects as message payload.\nAccessing the payload as JsonObject is a bit cumbersome as the type of the message parameter must be specified:\n\n```java\neb.registerHandler(\"test\", (EventBusBridge.EventBusMessage\u003cJsonObject\u003e msg) -\u003e {\n    assertEquals(\"world\", msg.body().getString(\"hello\"));\n});\neb.publish(\"test\", new JsonObject().put(\"hello\", \"world\"));\n\n```\n\nFor convenience, `msg.asJson()` will return an `Message\u003cJsonObject\u003e` so the code above can be simplified like this:\n\n```java\neb.registerHandler(\"test\", msg -\u003e {\n    assertEquals(\"world\", msg.asJson().body().getString(\"hello\"));\n});\neb.publish(\"test\", new JsonObject().put(\"hello\", \"world\"));\n\n```\n\n\n### Registering/Unregistering handlers\n\nThere are some gotchas when using lambda expressions and unregistering handlers for messages.\nFor example, this will fail:\n\n```java\neb.registerHandler(\"test\", this::myHandler):\neb.unregisterHandler(\"test\", this::myHandler);\n```\n\nsince the compiler will create different lambda classes for each occurrence of `this::myHandler`!\n\nIn order to make the most common de-registration case simple (de-register after receiving a message),\nthe message object has an unregister method that will unregister the current handler.\n\n```java\neb.registerHandler(\"test\", msg -\u003e { System.out.println(\"Got your message. Now leave me alone!\"); msg.unregister(); }); \n\n```\nNote one important caveat which is that `msg.unregister` will only work correctly if used while the handler is being called.\n\n### Using Proxies\n\nv1.1 added `connect` methods to specify the host and port to connect to as well as the URL to retrieve.\nTo connect via a `proxyHost` at `proxyPort`, call\n\n```\nEventBusBridge.connect(proxyPort, proxyHost, url, eb -\u003e {...}, options);\n```\n\nMake sure the URL is an absolute URL in this case.\n\n### Using SSL\n\nv1.2 added support for SSL. \nUse a `https` URL or pass your own `new HttpOptions().setSsl(true)` options.\nDepending on your needs, specify a trust store. Check the Vert.x docs for details.\n\n\n## Status\n\n1.2 - support for SSL. Use `new HttpOptions().setSsl(true).setVerifyHost(false)` if you need to connect to a server with a self-signed certificate. See EventBusBridgeSSLTest. \n Tested with Vert.x 3.0.0 and 3.1.0\n\n[![Build Status](https://drone.io/github.com/saffron-technology/vertx-eventbusbridge/status.png)](https://drone.io/github.com/saffron-technology/vertx-eventbusbridge/latest)\n\n## Installation\n\nSince it is early days, download the git project and run `mvn jar:jar` to get something you can add to your Java project.\nThe latest build is available here\n(https://drone.io/github.com/saffron-technology/vertx-eventbusbridge/files)\n\n## Feedback\n\nOpen a ticket or send an email to jochen.bedersdorfer (at) intel (dot) com\n\n## License\n\nLicensed under Apache License 2.0. See LICENSE file\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaffron-technology%2Fvertx-eventbusbridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaffron-technology%2Fvertx-eventbusbridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaffron-technology%2Fvertx-eventbusbridge/lists"}