Ballerina is a programming language developed by WSO2 mainly targeting modern Integration requirements.This slide deck discusses about File processing and websockets capabilities of the Ballerina platform.
3. • File-based data transfers are here to stay
• Cloud and on premise
• Extract, Transform, Load (ETL) requirements
• Different file formats
• Streaming large files
• Securely transfer files
File based data sharing
4. • File I/O as part of the Ballerina I/O
• Fine grained file access (Bytes, Characters)
• Coarse grained file access (Records)
• Large file transfer through streaming
• Connect with remote file systems (FTP,
SFTP, SMB, etc..)
File Processing with Ballerina
5. • Open
• List
• Create directory
• Copy
• Move
• Create new file
• Delete
Ballerina File API - Operations
6. function main (string[] args) {
file:File target = {path:"/tmp/result.txt"};
target.open(file:W);
boolean b = target.exists();
println("file exists: " + b);
file:File source = {path:"/tmp/result.txt"};
file:File destination = {path:"/tmp/copy.txt"};
file:copy(source, destination);
println("file copied: /tmp/result.txt to /tmp/copy.txt");
destination.delete();
println("file deleted: /tmp/copy.txt");
destination = {path:"/tmp/move.txt"};
file:move(source, destination);
}
Ballerina File API - Example
Open
Exists
Copy
Delete
Move
7. Ballerina I/O API
I/O APIs
Record I/O
RecordsCharacters
Bytes
I/O Channels: Files, Sockets, Devices, ….
BytesI/O
CharactersI/O
Console
I/O
DataI/O
Different record formats
8. • Read byte by byte
• Character by character
• Record by record
• Canonical byte representation
• Console I/O, Data I/O (Future)
Ballerina I/O API - Files
13. • Modern applications (especially web)
consumes large amount of data in real time
• Request-Response pattern no longer
sufficient
• HTTP (1.1 and prior) lives with hacks (AJAX
long polling, Streaming, etc.)
Why Websockets?
14. • Long-lived connections
• Bi-directional messaging (full-duplex)
• Low usage of headers (save bandwidth)
• Co-exists with HTTP
With Websockets
15. • Support for different frame types (text, binary,
ping, pong)
• Sub protocol support
• SSL support
• Live alongside HTTP
Websockets in Ballerina
16. • Expose ballerina service through websockets
• Executes different logic based on message
type (text, binary, ping, pong)
• Can configure base path and port which is
exposing
Websockets Server connector
17. Websockets Server Connector
Websockets service definition
Client initiates a connection
Client connected
Text frame received
Connection closed
Service configuration
18. Websockets Client Connector
• Creates a connection with a websocket service
• Supports sub protocols
• Text, Binary, Ping, Pong message types
• Supports security
19. • Visit Ballerina website
https://ballerinalang.org/
• Start with examples
https://ballerinalang.org/docs/by-example/
• Contribute
https://github.com/ballerinalang
Download and getting started
19