| Designed by | Sanjiva Weerawarana, James Clark, Sameera Jayasoma, Hasitha Aravinda, Srinath Perera, Frank Leymann and WSO2[1] |
|---|---|
| Developer | WSO2 |
| First appeared | 2017 |
| Typing discipline | Structural, strong, static, inferred |
| Implementation language | Java, Ballerina, TypeScript [2] |
| OS | Cross-platform |
| License | Apache License 2.0[3] |
| Website | ballerina |
| Influenced by | |
| Java, Javascript, Go, Rust, C#[4] | |
Ballerina is an open source general-purpose programming language and platform designed by WSO2 for cloud-era application programmers. It is easy to write and modify and is suitable for application programmers.[5][6][7]
It is an open source project [2] started in 2015 by architects from WSO2 as a code-based alternative to the configuration-based integration tools such as EAI, ESB, and workflow products.[8][9]
It has various constructs geared toward cloud-native development including support for modern data formats and protocols, reliability, distributed transactions, APIs, and event streams.[10][11][12]
Ballerina was designed by WSO2 to improve productivity for application developers that have to work with distributed cloud-native systems. The designers, who provided enterprise products in the integration space for over 10 years, used their knowledge of the industry when designing the language.[13][14] Ballerina was first publicly announced in 2017 and version 1.0 was released on September 10, 2019.[15]
Some key concepts in Ballerina include:
import ballerina/http;
service hello on new http:Listener(9090) {
resource function sayHello(http:Caller caller,
http:Request req) returns error? {
check caller->respond("Hello, World!");
}
}To start the service, navigate to the directory that contains the `.bal` file, and execute the `ballerina run` command below.
$ ballerina run hello_world.bal
[ballerina/http] started HTTP/WS listener 0.0.0.0:9090
curl http://localhost:9090/hello/sayHello
Hello, World!
import ballerina/http;
import ballerina/lang.'int;
import ballerina/io;
// Workers interact with each other by sending and receiving messages.
// Ballerina validates every worker interaction (send and receive)
// to avoid deadlocks.
public function main() {
worker w1 {
int w1val = checkpanic calculate("2*3");
// Sends a message asynchronously to the worker `w2`.
w1val -> w2;
// Receives a message from the worker `w2`.
int w2val = <- w2;
io:println("[w1] Message from w2: ", w2val);
// Sends messages synchronously to the worker `w3`. The worker `w1` will wait
// until the worker `w3` receives the message.
w1val ->> w3;
w2val -> w3;
// Flushes all messages sent asynchronously to the worker `w3`. The worker
// will halt at this point until all messages are sent or until the worker `w3`
// fails.
checkpanic flush w3;
}
// A worker can have an explicit return type, or else, if a return type is not mentioned,
// it is equivalent to returning ().
worker w2 {
int w2val = checkpanic calculate("17*5");
// Receives a message from the worker `w1`.
int w1val = <- w1;
io:println("[w2] Message from w1: ", w1val);
// Sends a message asynchronously to the worker `w1`.
w1val + w2val -> w1;
}
worker w3 {
intimport ballerina/grpc;
import ballerina/log;
service HelloWorld on new grpc:Listener(9090) {
resource function hello(grpc:Caller caller, string name,
grpc:Headers headers) {
log:printInfo("Server received hello from " + name);
string message = "Hello " + name;
// Reads custom headers in request message.
string reqHeader = headers.get("client_header_key") ?: "none";
log:printInfo("Server received header value: " + reqHeader);
// Writes custom headers to response message.
grpc:Headers resHeader = new;
resHeader.setEntry("server_header_key", "Response Header value");
// Sends response message with headers.
grpc:Error? err = caller->send(message, resHeader);
if (err is grpc:Error) {
log:printError("Error from Connector: " + err.message());
}
// Sends `completed` notification to caller.
grpc:Error? result = caller->complete();
if (result is grpc:Error) {
log:printError("Error in sending completed notification to caller",
err = result);
}
}
}|journal= (help)
By: Wikipedia.org
Edited: 2021-06-18 18:11:50
Source: Wikipedia.org