{"id":21401618,"url":"https://github.com/stardogventures/dropwizard-worker","last_synced_at":"2025-07-13T21:31:54.513Z","repository":{"id":57736265,"uuid":"117562114","full_name":"stardogventures/dropwizard-worker","owner":"stardogventures","description":"Simple asynchronous processing for Dropwizard, using SQS","archived":false,"fork":false,"pushed_at":"2019-04-09T15:10:22.000Z","size":35,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-07-04T21:12:26.947Z","etag":null,"topics":["aws","dropwizard","sqs","worker","worker-queue"],"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/stardogventures.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}},"created_at":"2018-01-15T15:26:06.000Z","updated_at":"2019-04-09T15:10:24.000Z","dependencies_parsed_at":"2022-08-24T01:10:54.407Z","dependency_job_id":null,"html_url":"https://github.com/stardogventures/dropwizard-worker","commit_stats":null,"previous_names":[],"tags_count":2,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stardogventures%2Fdropwizard-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stardogventures%2Fdropwizard-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stardogventures%2Fdropwizard-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stardogventures%2Fdropwizard-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stardogventures","download_url":"https://codeload.github.com/stardogventures/dropwizard-worker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225919754,"owners_count":17545335,"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":["aws","dropwizard","sqs","worker","worker-queue"],"created_at":"2024-11-22T15:28:38.826Z","updated_at":"2024-11-22T15:28:39.469Z","avatar_url":"https://github.com/stardogventures.png","language":"Java","readme":"# dropwizard-worker\n\nby Ian White, Stardog Ventures (@eonwhite)\n\nThis is a simple way to run asynchronous, decentralized jobs from a\nDropwizard service.\n\nThis is particularly useful for crons scheduled with Amazon CloudWatch,\nas described in this great post by Dan McKinley (@mcfunley):\n\n   https://blog.skyliner.io/a-simple-pattern-for-jobs-and-crons-on-aws-2f965e43932f\n   \nBut this worker also should be suitable for busy event-processing queues as well.\n\nThe basic pattern is:\n\n  - Create any number of jobs you want to run. They need to implement\n  `Consumer\u003cMap\u003cString,Object\u003e\u003e`, where the `Map` represents parameters\n  to your method.\n\n```java\nclass MyCron implements Consumer\u003c\u003cMap\u003cString,Object\u003e\u003e {\n    public void consume(Map\u003cString,Object\u003e params) {\n        // do something interesting here\n    }\n}\n```\n  - Build a `WorkerMethods` object that contains your list of `WorkMethods` available. Each\nWorkMethod gets a unique name for the method and a consumer. The names are important, since\nyou'll use those names to call the method remotely.\n\nIf you have some really simple methods, you may want to consider inlining them as lambdas.\n  \n```java\nWorkerMethods methods = WorkerMethods.of(ImmutableList.of(\n        WorkMethod.of(\"cron\", new MyCron()),\n        WorkMethod.of(\"ping\", params -\u003e System.out.println(\"pong\"))\n));\n```  \n  - Configure a WorkerManager with your configuration,\n  and the worker you are using for processing messages\n  (normally `SqsWorker`)\n  \n```java\nenv.lifecycle().manage(new WorkerManager(\n        \"worker\",\n        WorkerConfig.builder().maxThreads(20).build(),\n        new SqsWorker(sqsClient, \"queue-name\", env.metrics()),\n        env.metrics());\n```  \n  \n  - Send to the queue (from anywhere in your distributed system, such as for example CloudWatch)\n  messages in the format:\n  \n```\n  {\"method\":\u003cmethod\u003e}\n  or\n  {\"method\":\u003cmethod\u003e,\"params\":\u003cparams\u003e}\n  or\n  {\"method\":\u003cmethod\u003e,\"params\":\u003cparams\u003e,\"at\":\u003cmillis\u003e}\n```\n\nWhere `method` is the name of the method, `params` is an object containing\nyour parameters, and `at` is a millisecond timestamp of the time the message was\nqueued.\n\n  - You can also send messages with a `SqsSender` like so:\n  \n```java\nSqsSender sender = new SqsSender(sqsClient, \"queue-name\")\n```  \n\nFeatures:\n  - Scales up for busy queues, launching threads and polling as quickly\n  as possible, but automatically scaling down for infrequently used queues\n  to save money and resources.\n  - Builtin metrics for monitoring the state of your queue.\n  - Includes a Dropwizard Task to run methods manually.\n  \n#### Timezone-aware crons\n\nWhile it's generally better to schedule crons in UTC time, there are situations\nwhere you want a cron to run at a time in a local timezone (e.g. \"9 am Eastern time\"),\nadjusting for Daylight Savings time.\n\nCloudWatch however does not support timezone-aware cron scheduling.\n\nSo the solution is:\n\n  - Wrap your cron in a `TimeZoneCron` like so:\n```java\n     TimeZoneCron.of(new MyCron(), ZoneId.of(\"America/New_York\"))\n```\n  - TimeZoneCron will check for a `dst` property in the params. If `dst`\n  is set to `true`, the cron will only run when in Daylight Savings Time,\n  and if `dst` is `false`, the cron will only run when not in Daylight\n  Savings Time.\n  - Schedule *two* otherwise identical CloudWatch SQS events at the two\n  potential times (e.g. 9am Eastern time could be either 13:00 UTC or\n  14:00 UTC), one with `\"dst\":true` and one with `\"dst\":false`\n  - TimeZoneCron will run your cron only once, depending on whether it\n  is currently DST or not.\n  - The above could get screwy if you schedule your cron in the wee hours\n  of the morning during the DST changeover period, so don't do that.\n  \n#### Redis PubSub\n  \ndropwizard-worker can send and receive messages in the same format using Redis PubSub\nvia Jedis.\n\nThis can be useful instead of SQS in situations where you require\nmultiple-subscriber behavior -- for example to have your appservers subscribe\nto a cache invalidation mechanism.\n\nBecause the Jedis client handles its own polling, there is no need to use the `WorkerManager`\nwith Redis. You can instantiate `RedisWorker` to consume pubsub, and `RedisSender` to send\nmessages.\n\nSee the `RedisExample` example for how this works.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstardogventures%2Fdropwizard-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstardogventures%2Fdropwizard-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstardogventures%2Fdropwizard-worker/lists"}