Channel Adapter
Use a Channel Adapter to define the boundary between an integration flow and the transport, application, or broker channel that supplies or receives messages.
The adapter is usually implemented at the edge of the flow. Use connector clients for application APIs, services and listeners for inbound endpoints, and broker connectors only when the channel itself is Kafka, RabbitMQ, or JMS. Keep payloads typed, and keep endpoints and credentials in configurables.
API/SaaS channel adapter with connector client
A connector client adapts an external application API into the integration flow. Create the connection with managed connection settings, call the required connector operation, and pass the typed result into the next step.
- Visual Designer
- Ballerina Code
- Add the connector client connection for the application channel. See adding a connection; for this example, select the Jira connector as shown in adding the Jira connector.
- Configure the endpoint, authentication values, and other connection properties with project configurables. Use the connector-specific Jira setup guide and Jira connection configuration steps.
- Add the connector operation that reads from or writes to the application channel. Use the Jira action reference to select the project operation for this example.
- Map the connector response to the message shape used by the rest of the flow.
public function readProject(string projectKey) returns jira:Project|error {
return jiraAdapter->/api/'3/project/[projectKey];
}
HTTP service as inbound channel adapter
An HTTP service adapts an inbound HTTP channel into an integration flow. Define the service resource as the adapter entry point, receive a typed request payload, and return the typed response expected by the caller. See creating an HTTP service for the service setup flow.
- Visual Designer
- Ballerina Code
- Create an HTTP service for the inbound channel. See creating an HTTP service.
- Add the resource that represents the inbound adapter operation. Use resource inputs to define the request payload or parameters.
- Define the response payload type for the resource with response schemas.
- Add the flow logic that transforms or forwards the received message.
service /projects on projectListener {
resource function post lookup(ProjectRequest request) returns ProjectResponse|error {
jira:Project project = check readProject(request.projectKey);
return mapProject(project);
}
}
Broker-backed channel adapter
Use a broker listener when the channel is a messaging broker rather than an application API or HTTP endpoint. The service receives records from the broker, converts each record into the flow payload, and acknowledges or publishes through the connector according to the channel contract. Use the relevant broker guide, such as Kafka consumers, RabbitMQ services, or the JMS listener.
- Visual Designer
- Ballerina Code
- Create the broker listener for the channel. For Kafka, see creating a Kafka consumer; for RabbitMQ, see creating a RabbitMQ service; for JMS, see the JMS listener.
- Configure the broker endpoint, topic or queue, and credentials with configurables. For Kafka, use service configuration; for RabbitMQ, use listener configuration.
- Add the message-handling function for the broker event. For Kafka, use service configuration; for RabbitMQ, use event handlers.
- Convert the broker record to the typed payload used inside the flow.
service on projectEventListener {
remote function onConsumerRecord(ProjectEvent[] events) returns error? {
foreach ProjectEvent event in events {
check handleProjectEvent(event);
}
}
}