-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example Worker implementation to 04-worker-c8zio.
- Loading branch information
Showing
10 changed files
with
117 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
04-worker-c8zio/src/main/scala/camundala/worker/c8zio/C8WorkerClient.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package camundala.worker.c8zio | ||
|
||
import io.camunda.zeebe.client.ZeebeClient | ||
import io.camunda.zeebe.client.impl.oauth.OAuthCredentialsProviderBuilder | ||
import zio.{ZIO, ZIOAppDefault} | ||
|
||
import java.net.URI | ||
import java.time.Duration | ||
|
||
object C8WorkerClient extends ZIOAppDefault: | ||
|
||
override def run: ZIO[Any, Any, Any] = | ||
ZIO.acquireReleaseWith(zeebeClient)(_.closeClient()): client => | ||
for | ||
server <- ZIO.attempt( | ||
client | ||
.newTopologyRequest | ||
.send | ||
.join | ||
).forever.fork | ||
worker <- ZIO.attempt(client | ||
.newWorker() | ||
.jobType("publish-tweet") | ||
.handler(ExampleJobHandler()) | ||
.timeout(Duration.ofSeconds(10)) | ||
.open()).fork | ||
_ <- worker.join | ||
_ <- server.join | ||
yield () | ||
|
||
private lazy val zeebeClient = | ||
ZIO.attempt: | ||
ZeebeClient.newClientBuilder() | ||
.grpcAddress(URI.create(zeebeGrpc)) | ||
.restAddress(URI.create(zeebeRest)) | ||
.credentialsProvider(credentialsProvider) | ||
.build | ||
|
||
private lazy val zeebeGrpc = | ||
"https://dbd4cad1-5621-4d66-b14e-71c92456939a.bru-2.zeebe.camunda.io:443" | ||
private lazy val zeebeRest = | ||
"https://bru-2.zeebe.camunda.io:443/dbd4cad1-5621-4d66-b14e-71c92456939a/v2" | ||
private lazy val audience = "zeebe.camunda.io" | ||
private lazy val clientId = sys.env("CAMUNDA8_CLOUD_CLIENTID") | ||
private lazy val clientSecret = sys.env("CAMUNDA8_CLOUD_CLIENTSECRET") | ||
private lazy val oAuthAPI = "https://login.cloud.camunda.io/oauth/token" | ||
|
||
private lazy val credentialsProvider = | ||
new OAuthCredentialsProviderBuilder() | ||
.authorizationServerUrl(oAuthAPI) | ||
.audience(audience) | ||
.clientId(clientId) | ||
.clientSecret(clientSecret) | ||
.build | ||
|
||
extension (client: ZeebeClient) | ||
def closeClient() = | ||
ZIO.succeed(if client != null then client.close() else ()) | ||
|
||
end C8WorkerClient |
9 changes: 9 additions & 0 deletions
9
04-worker-c8zio/src/main/scala/camundala/worker/c8zio/C8WorkerHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package camundala.worker.c8zio | ||
|
||
/** To avoid Annotations (Camunda Version specific), we extend ExternalTaskHandler for required | ||
* parameters. | ||
*/ | ||
trait C8WorkerHandler: | ||
|
||
|
||
end C8WorkerHandler |
13 changes: 13 additions & 0 deletions
13
04-worker-c8zio/src/main/scala/camundala/worker/c8zio/ExampleJobHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package camundala.worker.c8zio | ||
|
||
import io.camunda.zeebe.client.api.response.ActivatedJob | ||
import io.camunda.zeebe.client.api.worker.{JobClient, JobHandler} | ||
|
||
class ExampleJobHandler extends JobHandler: | ||
|
||
def handle(client: JobClient, job: ActivatedJob): Unit = | ||
println(s"Handling Job: ${job}") | ||
client.newCompleteCommand(job.getKey).send().join() | ||
|
||
|
||
end ExampleJobHandler |
13 changes: 7 additions & 6 deletions
13
05-examples/twitter/04-c8-spring/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
# Local Docker Configuration | ||
zeebe.client.broker.gateway-address=127.0.0.1:26500 | ||
zeebe.client.security.plaintext=true | ||
#zeebe.client.broker.gateway-address=127.0.0.1:26500 | ||
#zeebe.client.security.plaintext=true | ||
|
||
# Cloud Configuration | ||
#zeebe.client.cloud.region=bru-2 | ||
#zeebe.client.cloud.clusterId=ad5279ee-dfe3-43af-86c3-34f6cf2e9683 | ||
#zeebe.client.cloud.clientId=7j31qDoCE4dDmLQqiPQp3dn2ecCFOq.w | ||
#zeebe.client.cloud.clientSecret=X_5T8x0VG._sQ9LACqnkeIRMmA5-iM0yf3O4lMAUXNkK20qex.eBN~cjGJAVSIDA | ||
camunda.client.mode=saas | ||
camunda.client.auth.client-id=L9n_ZQ3ehCtgPjTce8S7nabLGxhiVz3E | ||
camunda.client.auth.client-secret=tu9c98w~Ip~7T_esBjS_8PMGl0.34R898Yt29wwzhyeMCQO78eOx6.4rk6ucsnsE | ||
camunda.client.cluster-id=dbd4cad1-5621-4d66-b14e-71c92456939a | ||
camunda.client.region=bru-2 | ||
|
||
server.port=8887 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,4 +84,4 @@ | |
</bpmndi:BPMNShape> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</definitions> | ||
</definitions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters