{"id":13805849,"url":"https://github.com/mbknor/dropwizard-activemq-bundle","last_synced_at":"2025-04-27T02:31:57.631Z","repository":{"id":15886916,"uuid":"18628132","full_name":"mbknor/dropwizard-activemq-bundle","owner":"mbknor","description":"Use it when you need to send and receive JSON via ActiveMQ in your Dropwizard application","archived":false,"fork":false,"pushed_at":"2024-02-04T14:44:42.000Z","size":103,"stargazers_count":32,"open_issues_count":6,"forks_count":28,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-04T19:42:04.710Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mbknor.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-04-10T07:42:10.000Z","updated_at":"2024-02-06T00:41:53.000Z","dependencies_parsed_at":"2024-08-04T01:15:27.568Z","dependency_job_id":null,"html_url":"https://github.com/mbknor/dropwizard-activemq-bundle","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbknor%2Fdropwizard-activemq-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbknor%2Fdropwizard-activemq-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbknor%2Fdropwizard-activemq-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbknor%2Fdropwizard-activemq-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbknor","download_url":"https://codeload.github.com/mbknor/dropwizard-activemq-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251080402,"owners_count":21533091,"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:05.568Z","updated_at":"2025-04-27T02:31:57.269Z","avatar_url":"https://github.com/mbknor.png","language":"Java","funding_links":[],"categories":["Open Source"],"sub_categories":["Eclipse"],"readme":"Dropwizard ActiveMQ Bundle\r\n==================================\r\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.kjetland.dropwizard/dropwizard-activemq/badge.svg)](http://search.maven.org/#search%7Cga%7C1%7Cdropwizard-activemq)\r\n\r\n*Since Dropwizard ActiveMQ Bundle is written in Java 8, your app must also be compiled with Java 8*\r\n\r\nUse it when you need to send and receive JSON (jackson) via ActiveMq in your Dropwizard application.\r\n\r\nPlease have a look at the [Example application](https://github.com/mbknor/dropwizard-activemq-bundle/tree/master/example).\r\n\r\nChange History\r\n--------------\r\n\r\nVersion 0.5.2\r\n\r\n* Added support for object-messages\r\n\r\nVersion 0.5.1\r\n\r\n* Fixing sporadic issue where \"session is closed\" when ack'ing received message\r\n\r\nVersion 0.5.0\r\n\r\n* Add support to connect to multiple activeMq brokers\r\n* Upgraded to Dropwizard 1.0.2 and ActiveMQ 5.14.1\r\n\r\nVersion 0.4.0\r\n\r\n* First version released to Maven Central\r\n* Code is identical to version 0.3.13\r\n\r\nVersion 0.3.13\r\n\r\n* Upgraded to Dropwizard 0.9.1 and ActiveMQ 5.13.0\r\n\r\nVersion 0.3.12\r\n\r\n* Added support for receiving ActiveMQMapMessage as java.util.Map\r\n\r\nVersion 0.3.11\r\n\r\n* Added support for connecting to secure brokers\r\n* Upgraded to ActiveMQ client version 5.11.1\r\n\r\nVersion 0.3.10\r\n\r\n* Set correlationID on outgoing messages if sent in same thread as incoming message \r\n\r\nVersion 0.3.9\r\n\r\n* Now using ActiveMQ 5.10 and Dropwizard 0.7.1\r\n* Reduces info-logging\r\n\r\nVersion 0.3.8.1\r\n\r\n* Fixed [issue #6](https://github.com/mbknor/dropwizard-activemq-bundle/issues/6) - Improve handling of failing exceptionHandler\r\n\r\nVersion 0.3.7\r\n\r\n* Merged [Added raw jms message to exception handler](https://github.com/mbknor/dropwizard-activemq-bundle/pull/8)\r\n\r\nVersion 0.3.6\r\n\r\n* Fixed [issue #5](https://github.com/mbknor/dropwizard-activemq-bundle/issues/5) - Use less verbose errors when 'The Consumer is closed'\r\n\r\nVersion 0.3.5\r\n\r\n* Improved error handling for receiver + added healthCheck for each receiver\r\n* idleTimeout is now specified in mills\r\n* Added time to live for JMS message sending\r\n* Added more flexible option for creating messages by passing a function\r\n\r\nVersion 0.3.4 - 20140428\r\n\r\n* Removed resource-leakage when sending messages using multiple senders\r\n\r\nVersion 0.3.3 - 20140428\r\n\r\n* Added more pool-config options\r\n* HealthCheck is not using pooled factory anymore to prevent hang\r\n\r\nVersion 0.3.2 - 20140428\r\n\r\n* Added activeMQ-HealthCheck\r\n* Added max-give-up-time for graceful shutdown\r\n* Added more debug logging\r\n\r\nVersion 0.3.1 - 20140411\r\n\r\n* Added ActiveMQSenderFactory and JsonError\r\n\r\nVersion 0.3 - 20140411\r\n\r\n* It is now possible to change between queues and topics by prefixing the destination-name\r\n\r\nVersion 0.2 - 20140410\r\n\r\n* Added custom exception-handler\r\n\r\nVersion 0.1 - 20140410\r\n\r\n* Initial version\r\n\r\n\r\nMaven\r\n----------------\r\n\r\nAdd it as a dependency:\r\n\r\n```xml\r\n    \u003cdependency\u003e\r\n        \u003cgroupId\u003ecom.kjetland.dropwizard\u003c/groupId\u003e\r\n        \u003cartifactId\u003edropwizard-activemq\u003c/artifactId\u003e\r\n        \u003cversion\u003e INSERT LATEST VERSION HERE \u003c/version\u003e\r\n    \u003c/dependency\u003e\r\n```\r\n\r\nConfiguration\r\n------------\r\n\r\nYour config-class must implement ActiveMQConfigHolder like this:\r\n\r\n```java\r\npublic class Config extends Configuration implements ActiveMQConfigHolder {\r\n\r\n    @JsonProperty\r\n    @NotNull\r\n    @Valid\r\n    private ActiveMQConfig activeMQ;\r\n\r\n    public ActiveMQConfig getActiveMQ() {\r\n        return activeMQ;\r\n    }\r\n}\r\n```\r\n\r\n\r\nAnd add the following to your config.yml:\r\n\r\n```yaml\r\n\r\nactiveMQ:\r\n  brokerUrl: tcp://localhost:61616\r\n\r\n\r\n```\r\n\r\n(Almost?) All config-options:\r\n\r\n```yaml\r\n\r\nactiveMQ:\r\n  brokerUrl: failover:(tcp://broker1.com:61616,tcp://broker2.com:61616)?randomize=false\r\n  # brokerUsername: username\r\n  # brokerPassword: password\r\n  # shutdownWaitInSeconds: 20\r\n  # healthCheckMillisecondsToWait: 2000\r\n  # timeToLiveInSeconds: -1     (Default message time-to-live is off. Specify a maximum lifespan here in seconds for all messages.)\r\n  # trustedPackages: (To prevent malicious code from being deserialized. Needed if you want to receive plain object messages, see http://activemq.apache.org/objectmessage.html)\r\n  #   - com.some.package\r\n  #   - java.util\r\n\r\n  pool:\r\n    maxConnections: 1\r\n    maximumActiveSessionPerConnection: 3\r\n    blockIfSessionPoolIsFull: false\r\n    idleTimeoutMills: 30000\r\n    # expiryTimeoutMills:\r\n    createConnectionOnStartup: false\r\n    timeBetweenExpirationCheckMillis: 20000\r\n\r\n```\r\n\r\n\r\nUse it like this\r\n--------------------\r\n\r\n(Please have a look at the [Example application](https://github.com/mbknor/dropwizard-activemq-bundle/tree/master/example))\r\n\r\n```java\r\npublic class ActiveMQApp extends Application\u003cConfig\u003e {\r\n\r\n    public static void main(String[] args) throws Exception {\r\n        new ActiveMQApp().run(args);\r\n    }\r\n\r\n    private ActiveMQBundle activeMQBundle;\r\n\r\n    @Override\r\n    public void initialize(Bootstrap\u003cConfig\u003e configBootstrap) {\r\n\r\n        // Create the bundle and store reference to it\r\n        this.activeMQBundle = new ActiveMQBundle();\r\n        // Add the bundle\r\n        configBootstrap.addBundle(activeMQBundle);\r\n    }\r\n\r\n    @Override\r\n    public void run(Config config, Environment environment) throws Exception {\r\n\r\n\r\n        // Create a queue sender\r\n        ActiveMQSender sender = activeMQBundle.createSender(\"test-queue\", false);\r\n\r\n        // or like this:\r\n        ActiveMQSender sender2 = activeMQBundle.createSender(\"queue:test-queue\", false);\r\n\r\n        // where messages have a 60 second time-to-live:\r\n        ActiveMQSender sender3 = activeMQBundle.createSender(\"queue:test-queue\", false, Optional.of(60));\r\n\r\n        // Create a topic-sender\r\n        ActiveMQSender sender4 = activeMQBundle.createSender(\"topic:test-topic\", false);\r\n\r\n        // use it\r\n        sender.send( someObject );\r\n        sender.sendJson(\"{'a':2, 'b':3}\");\r\n\r\n        // If you require full control of message creation, pass a Java 8 function that takes a javax.jms.Session parameter:\r\n        sender.send((Session session) -\u003e {\r\n            TextMessage message = session.createTextMessage();\r\n            message.setText(\"{'a':2, 'b':3}\");\r\n            message.setJMSCorrelationID(myCorrelationId);\r\n            return message;\r\n        });\r\n\r\n\r\n        // Create a receiver that consumes json-strings using Java 8\r\n        activeMQBundle.registerReceiver(\r\n                \"test-queue\", // default is queue. Prefix with 'topic:' or 'queue:' to choose\r\n                (json) -\u003e System.out.println(\"json: \" + json),\r\n                String.class,\r\n                true);\r\n\r\n\r\n        // Create a receiver that consumes SomeObject via Json using Java 8\r\n        activeMQBundle.registerReceiver(\r\n                            \"test-queue-2\",\r\n                            (o) -\u003e System.out.println(\"Value from o: \" + o.getValue()),\r\n                            SomeObject.class,\r\n                            true);\r\n\r\n        // Create a receiver that consumes SomeObject via Json using Java 7\r\n        activeMQBundle.registerReceiver(\r\n                            \"test-queue-3\",\r\n                            new ActiveMQReceiver\u003cSomeObject\u003e() {\r\n                                @Override\r\n                                public void receive(SomeObject o) {\r\n                                    System.out.println\"Value from o: \" + o.getValue());\r\n                                }\r\n                            },\r\n                            SomeObject.class,\r\n                            true);\r\n    }\r\n}\r\n```\r\n\r\nTopics and queue\r\n----------------\r\nBy default all destination-names refers to *queues*.\r\nIf you want to specify topic (or queue), you prefix it with:\r\n\r\n* topic:\r\n* queue:\r\n\r\n\r\nCustom exception-handling\r\n-----------------\r\n\r\n```java\r\nactiveMQBundle.registerReceiver(\r\n    config.getInboundJmsQueue(),\r\n    (ManualRequest m) -\u003e myService.processMessage(m),\r\n    ManualRequest.class,\r\n    // Add your custom exception-handler here\r\n    (message, exception) -\u003e {\r\n        System.out.println(\"Error with this message: \" + message);\r\n        exception.printStackTrace();\r\n        return true;\r\n    });\r\n```\r\n\r\nConnecting to secure brokers\r\n----------------------------\r\n\r\nConnecting to a secure broker is possible by setting both the username (brokerUsername) and password (brokerPassword) in an application's config file.\r\n\r\nConnecting to multiple brokers\r\n------------------------------\r\n\r\nThe library has a second bundle that enables a dropwizard application to connect to multiple brokers. \r\nThis bundle will correctly register multiple healthchecks for each queue created, differentiating them using the brokerName given in the config\r\n\r\nUsage is the same with the following changes:\r\n\r\n(Please have a look at the [Multi Broker Example application](https://github.com/mbknor/dropwizard-activemq-bundle/tree/master/example/MultiQExampleApp.java))\r\n\r\n```java\r\n// Create the multi bundle and store reference to it\r\n    this.activeMQBundle = new ActiveMQMultiBundle();\r\n// Add the bundle\r\n    configBootstrap.addBundle(activeMQBundle);\r\n\r\n\r\npublic void run(MultiQConfig config, Environment environment) throws Exception {\r\n        MultiQResource multiQResource = new MultiQResource();\r\n        environment.jersey().register(multiQResource);\r\n        activeMQBundle.getActiveMQBundleMap().entrySet()\r\n            .stream()\r\n            .forEach(activeMQEntry-\u003eactivateQueue(multiQResource, activeMQEntry));\r\n}\r\n\r\nprivate void activateQueue(MultiQResource multiQResource, Map.Entry\u003cString, ActiveMQBundle\u003e activeMQEntry) {\r\n    String queueName = activeMQEntry.getKey();\r\n    ActiveMQBundle activeMQBundle = activeMQEntry.getValue();\r\n\r\n    // Set up the sender for our queue\r\n    multiQResource.addSender(queueName, activeMQBundle.createSender( queueName, false));\r\n\r\n    // Set up a receiver that just logs the messages we receive on our queue\r\n    activeMQBundle.registerReceiver(\r\n        queueName,\r\n        (message) -\u003e log.info(\"\\n*****\\nWe received a message on: {} from activeMq: \\n{}\\n*****\", queueName, message),\r\n        Message.class,\r\n        true);\r\n}\r\n```\r\n\r\nIn a real application you will have to handle which messages are sent / received to which broker based on your requirements. \r\nThe broker name will be your identification key for the mappings \r\n\r\nYou should use the MultiQConfig which is a map of ActiveMQConfig configs\r\n```yaml\r\nactiveMQConnections:\r\n  ieQueue:\r\n      brokerUrl: tcp://localhost:61616\r\n  gbQueue:\r\n      brokerUrl: tcp://localhost:61626\r\n```\r\n\r\nReceiving object messages\r\n-------------------------\r\nThe bundle also supports receiving plain object messages. The code required for receiving object messages is the same as \r\nfor json deserialized objects. The magic is happening internally in the library before the message is dispatched to the \r\nreceiver.\r\n\r\nTo avoid malicious code from being deserialized, you must configure trusted packages in the bundle configuration, i.e.\r\nthe packages containing the code you want to receive. More information can be found at \r\nhttp://activemq.apache.org/objectmessage.html . Default behaviour is to reject all packages.\r\n\r\n```yaml\r\nactiveMQ:\r\n  ...\r\n  trustedPackages:\r\n    - com.youpackages.*\r\n    - java.util\r\n```\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbknor%2Fdropwizard-activemq-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbknor%2Fdropwizard-activemq-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbknor%2Fdropwizard-activemq-bundle/lists"}