Back to Examples
- Binding patterns
- Typed binding pattern
- Wildcard binding pattern
- List binding patterns
- Rest binding pattern in list binding pattern
- Mapping binding pattern
- Rest binding pattern in mapping binding pattern
- Error binding pattern
- Rest binding pattern in error binding pattern
- Single use of typed binding patterns
- Single use of typed binding patterns with on fail clause
- Iterative use of typed binding patterns
- List binding pattern in match statement
- Mapping binding pattern in match statement
- Error binding pattern in match statement
- Query expressions
- Sort iterable objects
- Let clause
- Limit clause
- Join iterable objects
- Outer Join clause
- Query tables
- Create tables with a query
- Create maps with a query
- Create streams with a query
- On conflict clause
- Advanced conflict handling
- Iterate over XML with a query
- Nested query expressions
- Destructure records using a query
- Querying streams
- Aggregation
- JSON type
- Access JSON elements
- Access optional JSON elements
- Match statement with maps
- Convert from user-defined type to JSON
- Convert from table and XML to JSON
- Convert from JSON to user-defined type
- Cast JSON to user-defined type
- Resource method typing
- JSON numbers
- JSON to record
- JSON to record with projection
- JSONPath expressions
- Asynchronous function calls
- Named workers
- Sequence diagrams
- Wait for workers
- Strands
- Named worker return values
- Alternate wait
- Multiple wait
- Named workers and futures
- Inter-worker message passing
- Alternate receive
- Multiple receive
- Conditional send
- Inter-worker failure propagation
- Named worker with on fail clause
- Synchronize message passing
- Asynchronize message passing
- Flush
- Fork
Kafka consumer - SSL/TLS
The kafka:Consumer
connects to a Kafka server via SSL/TLS and then, receives payloads from the server. SSL/TLS can be enabled by configuring the secureSocket
, which requires a certificate and the protocol name. Further, the mode of security must be configured by setting the securityProtocol
to kafka:PROTOCOL_SSL
. Use this to connect to a Kafka server secured with SSL/TLS.
import ballerinax/kafka;
import ballerina/io;
type Order readonly & record {
int orderId;
string productName;
decimal price;
boolean isValid;
};
public function main() returns error? {
kafka:Consumer orderConsumer = check new ("localhost:9094", {
groupId: "order-group-id",
topics: ["order-topic"],
// Provide the relevant secure socket configurations by using `kafka:SecureSocket`.
secureSocket: {
cert: "./resources/path/to/public.crt",
protocol: {
// Provide the relevant security protocol.
name: kafka:SSL
}
},
// Provide the type of the security protocol to use in the broker connection.
securityProtocol: kafka:PROTOCOL_SSL
});
// Polls the consumer for payload.
Order[] orders = check orderConsumer->pollPayload(1);
from Order 'order in orders
where 'order.isValid
do {
io:println(string `Received valid order for ${'order.productName}`);
};
}
Prerequisites
- • Start a Kafka broker instance configured to use SSL/TLS.
Run the program by executing the following command.
$ bal run kafka_client_consumer_sasl.balReceived valid order for Sport shoe
Tip: Run the Kafka client given in the Kafka producer - SSL/TLS example to produce some messages to the topic.
Related links
PreviousSASL authentication
NextSASL authentication