Learn how to start and interact with workflows and services using the Infinitic client
The Infinitic Client is your interface to interact with workflows and services. It allows you to start workflows, send signals, query status, and manage running instances from your application code.
import io.infinitic.clients.InfiniticClientimport io.infinitic.transport.config.TransportConfigfun main() { val client = InfiniticClient.builder() .setName("my-client") .setTransport( TransportConfig.builder() .setPulsar( PulsarConfig.builder() .setBrokerServiceUrl("pulsar://localhost:6650") .setWebServiceUrl("http://localhost:8080") .setTenant("infinitic") .setNamespace("dev") .build() ) .build() ) .build() // Use the client val workflow = client.newWorkflow(OrderWorkflow::class.java) val result = workflow.processOrder(orderId) // Close when done client.close()}
import io.infinitic.clients.InfiniticClientfun main() { // Load from resources val client = InfiniticClient.fromYamlResource("/infinitic-client.yml") // Or from file // val client = InfiniticClient.fromYamlFile("config/infinitic-client.yml") // Or from string // val client = InfiniticClient.fromYamlString(yamlContent) // Use the client val workflow = client.newWorkflow(OrderWorkflow::class.java) val result = workflow.processOrder(orderId) client.close()}
val client = InfiniticClient.fromYamlResource("/infinitic-client.yml")// Create workflow with metadataval workflow = client.newWorkflow( OrderWorkflow::class.java, tags = setOf("user:${userId}"), meta = mapOf( "priority" to "high".toByteArray(), "region" to "us-west".toByteArray(), "version" to "2.0".toByteArray() ))val result = workflow.processOrder(orderId)client.close()
val client = InfiniticClient.fromYamlResource("/infinitic-client.yml")// Get workflow by tagval workflow = client.getWorkflowByTag( OrderWorkflow::class.java, tag = "order:${orderId}")// Interact with the workflowval status = workflow.getStatus()// Get all IDs associated with a tagval ids: Set<String> = client.getIds(workflow)println("Found ${ids.size} workflows with tag")client.close()
val client = InfiniticClient.fromYamlResource("/infinitic-client.yml")val workflow = client.getWorkflowById( OrderWorkflow::class.java, workflowId = workflowId)// Retry specific task by IDclient.retryTasksAsync(workflow, taskId = "task-123").get()// Or retry by statusimport io.infinitic.workflows.DeferredStatusclient.retryTasksAsync( workflow, taskStatus = DeferredStatus.FAILED).get()// Or retry by service classclient.retryTasksAsync( workflow, taskStatus = DeferredStatus.FAILED, taskClass = PaymentService::class.java).get()client.close()
val client = InfiniticClient.fromYamlResource("/infinitic-client.yml")val workflow = client.getWorkflowById( OrderWorkflow::class.java, workflowId = workflowId)// Complete all timersclient.completeTimersAsync(workflow).get()// Or complete specific timer by method IDclient.completeTimersAsync(workflow, id = "method-id").get()client.close()
The client manages resources that should be properly closed:
fun main() { val client = InfiniticClient.fromYamlResource("/infinitic-client.yml") try { // Use the client val workflow = client.newWorkflow(OrderWorkflow::class.java) workflow.processOrder(orderId) } finally { // Close client to release resources client.close() } // Or use try-with-resources (Java) / use (Kotlin) InfiniticClient.fromYamlResource("/infinitic-client.yml").use { client -> val workflow = client.newWorkflow(OrderWorkflow::class.java) workflow.processOrder(orderId) }}
The close() method:
Cancels ongoing operations
Waits for in-flight messages (up to shutdownGracePeriodSeconds)
Deletes the client topic
Closes transport connections
From InfiniticClient.kt:99-120, the client implements proper cleanup with a configurable grace period for shutdown.