03-worker
Use this to add Company specific Worker stuff like the configuration of the auth method.
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
:
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.
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.
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.
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
):
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]