This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina.log; | |
import ballerina.io; | |
import ballerina.net.http; | |
// This service is a participant in the distributed transaction. It will get infected when it receives a transaction | |
// context from the participant. The transaction context, in the HTTP case, will be passed in as custom HTTP headers. | |
@http:configuration { | |
basePath:"/", | |
host:"localhost", | |
port:8890 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by the protocol buffer compiler. DO NOT EDIT! | |
// source: ExampleServices.proto | |
package com.example.grpc; | |
/** | |
* Protobuf type {@code com.example.grpc.HelloRequest} | |
*/ | |
public final class HelloRequest extends | |
com.google.protobuf.GeneratedMessageV3 implements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the server implementation for the client streaming scenario. | |
import ballerina/grpc; | |
import ballerina/log; | |
@grpc:ServiceConfig { | |
name: "HelloWorld", | |
clientStreaming: true | |
} | |
service HelloWorld on new grpc:Listener(9090) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerina/jballerina.java; | |
public function main() { | |
LogRecord logRecord = { | |
time: "2021-05-04T10:32:13.220+05:30", | |
level: "DEBUG", | |
module: "foo/bar", | |
message: "debug \n message", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service RouteGuide { | |
rpc GetFeature(Point) returns (Feature) {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service "RouteGuide" on new grpc:Listener(8980) { | |
remote function GetFeature(Point point) returns Feature|error { | |
foreach Feature feature in FEATURES { | |
if feature.location == point { | |
return feature; | |
} | |
} | |
return {location: point, name: ""}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RouteGuideClient ep = check new ("http://localhost:8980"); | |
Feature feature = check ep->GetFeature({latitude: 406109563, longitude: -742186778}); | |
io:println(`GetFeature: lat=${feature.location.latitude}, lon=${feature.location.longitude}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service RouteGuide { | |
rpc ListFeatures(Rectangle) returns (stream Feature) {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service "RouteGuide" on new grpc:Listener(8980) { | |
remote function ListFeatures(Rectangle rectangle) returns stream<Feature, grpc:Error?>|error { | |
int left = int:min(rectangle.lo.longitude, rectangle.hi.longitude); | |
int right = int:max(rectangle.lo.longitude, rectangle.hi.longitude); | |
int top = int:max(rectangle.lo.latitude, rectangle.hi.latitude); | |
int bottom = int:min(rectangle.lo.latitude, rectangle.hi.latitude); | |
Feature[] selectedFeatures = from var feature in FEATURES | |
where feature.name != "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RouteGuideClient ep = check new ("http://localhost:8980"); | |
// Server streaming | |
Rectangle rectangle = { | |
lo: {latitude: 400000000, longitude: -750000000}, | |
hi: {latitude: 420000000, longitude: -730000000} | |
}; | |
stream<Feature, grpc:Error?> features = check ep->ListFeatures(rectangle); | |
error? e = features.forEach(function(Feature f) { |