Skip to main content

Supported Protocols

You're reading Integration 5.0.0. The newest release is 5.1.0, and Cloud has the newest features. Go to the newest release

WSO2 Integrator, powered by Ballerina, provides native support for a wide range of communication protocols used in integration scenarios. Each protocol is implemented as a Ballerina module with type-safe clients, listeners, and services.

HTTP and web protocols​

ProtocolModuleDescriptionKey Features
HTTP/1.1ballerina/httpStandard HTTP protocolREST APIs, content negotiation, compression, caching
HTTP/2ballerina/httpMultiplexed HTTP protocolServer push, stream prioritization, header compression
WebSocketballerina/websocketFull-duplex communication over TCPReal-time messaging, binary and text frames, ping/pong
WebSubballerina/websub, ballerina/websubhubW3C WebSub pub/sub protocolContent distribution, webhook-based subscriptions
GraphQLballerina/graphqlGraphQL query language protocolQueries, mutations, subscriptions, schema introspection
gRPCballerina/grpcGoogle Remote Procedure CallUnary, server streaming, client streaming, bidirectional streaming

HTTP example​

import ballerina/http;

// HTTP/1.1 service
service /api on new http:Listener(8080) {
resource function get greeting() returns string {
return "Hello, World!";
}
}

// HTTP/2 client
http:Client http2Client = check new ("https://api.example.com", {
httpVersion: http:HTTP_2_0
});

Messaging protocols​

ProtocolModuleDescriptionKey Features
Apache Kafkaballerinax/kafkaDistributed event streamingProducer, consumer, consumer groups, topic management
RabbitMQballerinax/rabbitmqAMQP messaging brokerExchanges, queues, bindings, message acknowledgment
MQTTballerinax/mqttLightweight IoT messagingQoS levels, retained messages, last will, topic wildcards
NATSballerinax/natsCloud-native messagingPub/sub, request/reply, queue groups
NATS Streamingballerinax/stanStreaming extension for NATSDurable subscriptions, message replay, at-least-once delivery
JMSballerinax/java.jmsJava Message ServiceQueues, topics, durable subscribers, message selectors
Azure Service Busballerinax/asbAzure cloud messagingQueues, topics, sessions, dead-letter queues

Kafka example​

import ballerinax/kafka;

kafka:Producer producer = check new ("localhost:9092");

check producer->send({
topic: "orders",
value: {orderId: "ORD-001", amount: 99.99}
});

// Consumer
kafka:Consumer consumer = check new ("localhost:9092", {
groupId: "order-processors",
topics: ["orders"]
});

kafka:ConsumerRecord[] records = check consumer->poll(1);

Transport protocols​

ProtocolModuleDescriptionKey Features
TCPballerina/tcpTransmission Control ProtocolRaw socket communication, byte-level I/O
UDPballerina/udpUser Datagram ProtocolConnectionless communication, broadcast/multicast

TCP example​

import ballerina/tcp;

// TCP listener
service on new tcp:Listener(9090) {
remote function onConnect(tcp:Caller caller) returns tcp:ConnectionService {
return new EchoService();
}
}

service class EchoService {
*tcp:ConnectionService;

remote function onBytes(tcp:Caller caller, readonly & byte[] data) returns byte[]|tcp:Error? {
return data; // Echo back
}
}

File transfer protocols​

ProtocolModuleDescriptionKey Features
FTPballerina/ftpFile Transfer ProtocolUpload, download, list, directory operations
SFTPballerina/ftpSSH File Transfer ProtocolEncrypted file transfer, key-based authentication

FTP example​

import ballerina/ftp;

// FTP client
ftp:Client ftpClient = check new ({
host: "ftp.example.com",
port: 21,
auth: {
credentials: {username: "user", password: "pass"}
}
});

// Upload a file
stream<io:Block, io:Error?> fileStream = check io:fileReadBlocksAsStream("data.csv");
check ftpClient->put("/uploads/data.csv", fileStream);

// FTP listener for file events
listener ftp:Listener ftpListener = check new ({
host: "ftp.example.com",
auth: {credentials: {username: "user", password: "pass"}},
path: "/incoming",
pollingInterval: 30
});

service on ftpListener {
remote function onFileChange(ftp:WatchEvent & readonly event) {
foreach ftp:FileInfo file in event.addedFiles {
io:println("New file: ", file.name);
}
}
}

Email protocols​

ProtocolModuleDescriptionKey Features
SMTPballerina/emailSimple Mail Transfer ProtocolSend emails with attachments, HTML content
POP3ballerina/emailPost Office Protocol v3Receive and download emails
IMAP4ballerina/emailInternet Message Access ProtocolRead, search, and manage emails on server

Email example​

import ballerina/email;

// Send email via SMTP
email:SmtpClient smtp = check new ("smtp.example.com", "[email protected]", "password");

check smtp->sendMessage({
subject: "Order Confirmation",
body: "Your order has been processed.",
contentType: "text/plain"
});

// Listen for emails via IMAP
listener email:ImapListener imapListener = check new ({
host: "imap.example.com",
username: "[email protected]",
password: "password",
pollingInterval: 60
});

service "emailObserver" on imapListener {
remote function onMessage(email:Message message) {
io:println("From: ", message.sender);
io:println("Subject: ", message.'from);
}
}

Protocol comparison​

ProtocolPatternDelivery GuaranteeOrderingUse Case
HTTPRequest/ResponseAt-most-onceN/AREST APIs, webhooks
gRPCRequest/Response, StreamingAt-most-oncePer streamMicroservice-to-microservice
GraphQLRequest/ResponseAt-most-onceN/AFlexible API queries
WebSocketBidirectional streamingAt-most-oncePer connectionReal-time updates
KafkaPub/SubAt-least-once, Exactly-oncePer partitionEvent streaming, log aggregation
RabbitMQPub/Sub, QueueAt-least-oncePer queueTask distribution, async processing
NATSPub/Sub, Request/ReplyAt-most-onceNoneLightweight cloud messaging
MQTTPub/SubQoS 0/1/2Per topicIoT, edge devices
JMSPub/Sub, QueueAt-least-oncePer queueEnterprise messaging
TCPStreamReliable, orderedYesCustom binary protocols
UDPDatagramUnreliableNoneDiscovery, broadcast

See also​

Was this page helpful?