-
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 Worker implementation to 04-worker-c7spring.
- Loading branch information
Showing
14 changed files
with
516 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,133 @@ | ||
# 03-worker | ||
# 03-worker | ||
Use this to add Company specific Worker stuff like the configuration of the auth method. | ||
|
||
@:callout(info) | ||
Workers are a bit more complex as there is a specific implementation you have to provide. | ||
|
||
This will hopefully be simplified in the future. | ||
|
||
For now, you have to provide a couple of files, as explained below. | ||
@:@ | ||
|
||
The following structure is generated by `./helperCompany.scala init`: | ||
|
||
```bash | ||
03-worker/src | ||
| main/resources | ||
| main/scala/company/worker | ||
| | CompanyEngineContext.scala | ||
| | CompanyPasswordFlow.scala | ||
| | CompanyRestApiClient.scala | ||
| | CompanyWorkerHandler.scala | ||
| test/scala/company/worker | ||
``` | ||
|
||
## CompanyEngineContext | ||
Depending on the Camunda Engine and Authentication you use, you have to provide the EngineContext. | ||
|
||
```scala | ||
package mycompany.camundala.worker | ||
|
||
import camundala.camunda7.worker.Camunda7Context | ||
import scala.compiletime.uninitialized | ||
import scala.reflect.ClassTag | ||
|
||
@SpringConfiguration | ||
class CompanyEngineContext extends Camunda7Context: | ||
|
||
@Autowired() | ||
var restApiClient: CompanyRestApiClient = uninitialized | ||
|
||
override def sendRequest[ServiceIn: Encoder, ServiceOut: Decoder: ClassTag]( | ||
request: RunnableRequest[ServiceIn] | ||
): SendRequestType[ServiceOut] = | ||
restApiClient.sendRequest(request) | ||
|
||
end CompanyEngineContext | ||
``` | ||
Basically you override the sendRequest to use your RestApiClient with the specific auth-method. | ||
|
||
## CompanyPasswordFlow | ||
Configure the Token Service - this is tested only with Keycloak. | ||
|
||
```scala | ||
package mycompany.camundala.worker | ||
|
||
import camundala.camunda7.worker.oauth.OAuthPasswordFlow | ||
|
||
trait CompanyPasswordFlow extends OAuthPasswordFlow: | ||
|
||
lazy val fssoRealm: String = sys.env.getOrElse("FSSO_REALM", "myRealm") | ||
// default is a local keycloak server on colime docker environment | ||
lazy val fssoBaseUrl = sys.env.getOrElse("FSSO_BASE_URL", s"http://host.lima.internal:8090") | ||
|
||
override lazy val client_id = sys.env.getOrElse("FSSO_CLIENT_NAME", "myClientKey") | ||
override lazy val client_secret = sys.env.getOrElse("FSSO_CLIENT_SECRET", "myClientSecret") | ||
override lazy val scope = sys.env.getOrElse("FSSO_SCOPE", "myScope") | ||
override lazy val username = sys.env.getOrElse("FSSO_TECHUSER_NAME", "myTechUser") | ||
override lazy val password = sys.env.getOrElse("FSSO_TECHUSER_PASSWORD", "myTechUserPassword") | ||
|
||
end CompanyPasswordFlow | ||
``` | ||
## CompanyRestApiClient | ||
Some specific configuration or authentication for the RestApiClient. | ||
|
||
```scala | ||
package mycompany.camundala.worker | ||
|
||
import camundala.camunda7.worker.RestApiClient | ||
import camundala.worker.CamundalaWorkerError.* | ||
import sttp.client3.* | ||
|
||
@SpringConfiguration | ||
class CompanyRestApiClient extends RestApiClient, CompanyPasswordFlow: | ||
|
||
override protected def auth( | ||
request: Request[Either[String, String], Any] | ||
)(using context: EngineRunContext | ||
): Either[ServiceAuthError, Request[Either[String, String], Any]] = | ||
tokenService.adminToken() | ||
.map: | ||
request.addToken | ||
end auth | ||
|
||
end CompanyRestApiClient | ||
``` | ||
## CompanyWorkerHandler | ||
|
||
The Company's base class, you can provide super classes for each Worker type. | ||
See [Workers] for more information on these types. | ||
|
||
Example (generated by `./helperCompany.scala init`): | ||
|
||
```scala | ||
package mycompany.camundala.worker | ||
|
||
import camundala.camunda7.worker.C7WorkerHandler | ||
import scala.reflect.ClassTag | ||
|
||
/** | ||
* Add here company specific stuff, to run the Workers. | ||
* You also define the implementation of the WorkerHandler here. | ||
*/ | ||
trait CompanyWorkerHandler extends C7WorkerHandler | ||
|
||
trait CompanyInitWorkerDsl[ | ||
In <: Product: InOutCodec, | ||
Out <: Product: InOutCodec, | ||
InitIn <: Product: InOutCodec, | ||
InConfig <: Product: InOutCodec | ||
] extends CompanyWorkerHandler, InitWorkerDsl[In, Out, InitIn, InConfig] | ||
|
||
trait CompanyCustomWorkerDsl[ | ||
In <: Product: InOutCodec, | ||
Out <: Product: InOutCodec | ||
] extends CompanyWorkerHandler, CustomWorkerDsl[In, Out] | ||
|
||
trait CompanyServiceWorkerDsl[ | ||
In <: Product: InOutCodec, | ||
Out <: Product: InOutCodec, | ||
ServiceIn: InOutEncoder, | ||
ServiceOut: InOutDecoder: ClassTag | ||
] extends CompanyWorkerHandler, ServiceWorkerDsl[In, Out, ServiceIn, ServiceOut] | ||
``` |
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
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
Oops, something went wrong.