Skip to content

Instantly share code, notes, and snippets.

View daneshk's full-sized avatar

Danesh Kuruppu daneshk

View GitHub Profile
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
@daneshk
daneshk / HelloRequest.java
Last active September 10, 2018 18:52
Generated java code for HelloRequest message
// 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 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) {
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",
service RouteGuide {
rpc GetFeature(Point) returns (Feature) {}
}
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: ""};
}
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}`);
service RouteGuide {
rpc ListFeatures(Rectangle) returns (stream Feature) {}
}
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 != ""
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) {