{"id":15583378,"url":"https://github.com/vmj/skew-consumer","last_synced_at":"2025-03-29T08:23:35.522Z","repository":{"id":139272973,"uuid":"69035038","full_name":"vmj/skew-consumer","owner":"vmj","description":"Camel, CDI, Java SE, Resin, Rasperri Pi 3 (example)","archived":false,"fork":false,"pushed_at":"2017-06-16T22:15:49.000Z","size":99,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-03T22:40:52.041Z","etag":null,"topics":["activemq","camel","cdi","competing-consumers","consumer","enterprise","java-se","patterns","resin"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vmj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2016-09-23T15:00:42.000Z","updated_at":"2017-05-12T09:04:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"d8acc1c2-e654-4bc3-91a9-a0e4d6925127","html_url":"https://github.com/vmj/skew-consumer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmj%2Fskew-consumer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmj%2Fskew-consumer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmj%2Fskew-consumer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmj%2Fskew-consumer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vmj","download_url":"https://codeload.github.com/vmj/skew-consumer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246158077,"owners_count":20732716,"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":["activemq","camel","cdi","competing-consumers","consumer","enterprise","java-se","patterns","resin"],"created_at":"2024-10-02T20:07:43.851Z","updated_at":"2025-03-29T08:23:35.515Z","avatar_url":"https://github.com/vmj.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Competing Polling Consumers\n#### Camel, CDI, Java SE, and a fleet of Rasperry Pis on Resin.io\n\nThis is an example of combining two EIPs (Enterprise Integration Patterns) in Camel:\n\n * Competing Consumers: message from a queue goes to one of the consumers.\n * Polling Consumers: the consumers pull a message to work on when they are ready to do so.\n\nTo make this more interesting, this also demos\nhow to integrate Apache Camel and CDI (Contexts and Dependency Injection) in a Java SE application.\nThose technologies are typically used in Java EE environment.\n\nFurthermore, we're going to deploy this to a cluster of Rasperry Pis, using Resin.io.\n\n:)\n\n## Setting up the demo message broker\n\nDownload ActiveMQ from apache.org.\nThen extract it and start it.\n\n    $ mkdir -p ~/demo\n    $ cd demo\n    $ wget http://archive.apache.org/dist/activemq/5.14.1/apache-activemq-5.14.1-bin.tar.gz\n    $ tar xzvf apache-activemq-5.14.1-bin.tar.gz\n    $ cd apache-activemq-5.14.1/bin\n    $ ./activemq console\n\nNow open the ActiveMQ web console at http://127.0.0.1:8161/admin/ (the credentials are admin:admin).\n\n## Running the app locally\n\nFirst, clone the source code:\n\n    $ git clone https://github.com/vmj/skew-consumer.git\n    $ cd skew-consumer\n\nYou can try the app locally (replace `./gradlew` with `gradlew.bat` if you're on Windows):\n\n    $ ./gradlew installDist\n    $ CONSUMER_REQUESTS_ENDPOINT_URI=\"stomp:queue:consumer.requests\" \\\n      CONSUMER_RESPONSES_ENDPOINT_URI=\"stomp:queue:consumer.responses\" \\\n      ./skew-consumer-app/build/install/skew-consumer-app/bin/skew-consumer-app\n\nI know its a long name for a script :)\n\n## Sending a message from ActiveMQ console\n\nNow send messages using the ActiveMQ web console.\nThe brokerUrl in the stomp component defaults to localhost,\nso the app and ActiveMQ should be talking to each other.\n\n * With one instance of consumer running, switch to ActiveMQ web console.\n * Click `Queues` and you should see `consumer.requests` queue listed,\n   with one consumer.\n * Click the `Send To` link on that row.\n * Type \"Hello\" to the `Message body` text area, and click `Send`.\n * You should now see that there's one message enqueued and one message\n   dequeued.\n * Refresh the page after a few seconds (the consumer sleeps for a while to imitate work)\n * You should now see `consumer.responses` queue listed, with one pending message.\n * Click the queue name (or the `Browse` link), then click the message ID of the message.\n * You should see the same \"Hello\" in the message details.\n\n## Running the app in Docker\n\nIf you have docker installed, you can, alternatively, run the app in\ndocker:\n\n    $ ./gradlew dockerResources\n    $ cd skew-consumer-app/build/docker\n    $ docker build --rm --tag=vmj0/skew-consumer-app:latest .\n\nNote that you will still need to pass those environment variables for\nthe app to work.\n\n    $ docker run --rm --read-only \\\n      -e CONSUMER_REQUESTS_ENDPOINT_URI=\"stomp:queue:consumer.requests?brokerURL=tcp://192.168.43.118:61613\" \\\n      -e CONSUMER_RESPONSES_ENDPOINT_URI=\"stomp:queue:consumer.responses?brokerURL=tcp://192.168.43.118:61613\" \\\n      vmj0/skew-consumer-app:latest\n\nNaturally, change the IP to match the ActiveMQ server address.\n\n## Running the app on your Resin app fleet\n\n\n### Hardware\n\nI've got two of the following:\n\n  * Rasperry Pi 3 Model B\n  * Transcend microSDHC class 10 32GB (Premium 400x UHS-I)\n  * USB A - Micro B power cable\n\nI'm powering both of them with:\n\n  * Fuj:tech 7 port USB hub with 4A power supply\n\nTo prepare the SD cards:\n\n  * A linux laptop with SD card reader (needs a microSD adapter)\n\n\n### Sign up to Resin.io\n\nSign up or login to resin.io and create a new app.  Then download the\nResinOS .img for the app, specifying the WiFi SSID and password (if it is\nan open network, just an empty password).\n\n### Preparing the SD card\n\nOn the laptop, stick the SD card (using the adapter) to the reader.\n\nThen, as root:\n\n    $ fdisk -l\n    ...\n    Disk /dev/mmcblk0: 32.2GB, ...\n    ...\n      Device       Boot ... System\n    $ dd if=/tmp/resin-myapp-x.x.x-y.y.y-abcdef.img of=/dev/mmcblk0 bs=65536\n    ...\n    $ fdisk -l\n    ...\n    Dist /dev/mmcblk0: 32.2GB, ...\n    ...\n      Device       Boot ... System\n    /dev/mmcblk0p1   *      W95 FAT16 (LBA)\n    /dev/mmcblk0p2          Linux\n    /dev/mmcblk0p3          Linux\n    /dev/mmcblk0p4          W95 Ext'd (LBA)\n    /dev/mmcblk0p5          W95 FAT16 (LBA)\n    /dev/mmcblk0p6          Linux\n    $ sync\n\nAbove, `x.x.x` is the ResinOS version number, `y.y.y` is the supervisor version number,\nand `abcdef` is your app hash I guess.\n\nYou can now take the card out and do the same with the next card.\n\n### Plug the hardware\n\nPut the SD cards into the RPi3s and plug the power cords.\n\nFinally, go the the resin.io application dashboard and marvel as the devices come up :)\n\n### Installing the app on your Resin app fleet\n\nBuild the required Docker resources (Dockerfile and the app distribution).\n\n    $ ./gradlew -Presin dockerResources\n\nNote the `-Presin` argument.  It causes the build to generate ARMv7hf compliant Dockerfile.\n\nThen set up your Resin.io repository:\n\n    $ mkdir -p ~/my-app\n    $ cp skew-consumer-app/build/docker/* ~/my-app\n    $ cd ~/my-app\n    $ git init .\n    $ git add *\n    $ git commit -m \"Initial commit.\"\n    $ git remote add \u003cyour-resin-app-endpoint\u003e\n    $ git push resin master\n\nYou will now see in Resin app dashboard as the RPis start upgrading.\n\nYou will notice from the logs that they fail to initialize, but do not crash.\nTo fix this, define the app wide env vars in the Resin web console:\n\n    CONSUMER_REQUESTS_ENDPOINT_URI=\"stomp:queue:consumer.requests?brokerURL=tcp://192.168.43.118:61613\"\n    CONSUMER_RESPONSES_ENDPOINT_URI=\"stomp:queue:consumer.responses?brokerURL=tcp://192.168.43.118:61613\"\n\nNaturally, replace the IP address with your own where the ActiveMQ is running.\n\nResin will automatically restart your app containers.\n\nAgain, play with the ActiveMQ web console and send messages to the requests queue,\nand watch one of the RPis pick it, handle it, and reply to responses queue.\nIf you still have the local version(s) running, they will be competing for messages, too.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmj%2Fskew-consumer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvmj%2Fskew-consumer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmj%2Fskew-consumer/lists"}