-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support emitting JSON to topics (#246)
- Loading branch information
1 parent
d890be6
commit 958eb78
Showing
7 changed files
with
172 additions
and
3 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
samples/js/js-doc-snippets/proto/com/example/json/json_api.proto
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
syntax = "proto3"; | ||
package com.example.json; | ||
|
||
// tag::service[] | ||
import "google/protobuf/any.proto"; | ||
import "google/protobuf/empty.proto"; | ||
import "akkaserverless/annotations.proto"; | ||
|
||
message KeyValue { | ||
string key = 1; | ||
int32 value = 2; | ||
} | ||
|
||
service MyService { | ||
option (akkaserverless.codegen) = { | ||
action: {} | ||
}; | ||
|
||
rpc Consume(google.protobuf.Any) returns (google.protobuf.Empty) { | ||
option (akkaserverless.method).eventing.in = { | ||
topic: "notifications" | ||
}; | ||
} | ||
|
||
rpc Produce(KeyValue) returns (google.protobuf.Any) { // <1> | ||
option (akkaserverless.method).eventing.out = { // <2> | ||
topic: "notifications" // <3> | ||
}; | ||
} | ||
|
||
} | ||
// end::service[] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2021 Lightbend Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* This code was initialised by Akka Serverless tooling. | ||
* As long as this file exists it will not be re-generated. | ||
* You are free to make changes to this file. | ||
*/ | ||
|
||
import { Action } from "@lightbend/akkaserverless-javascript-sdk"; | ||
import { replies } from '@lightbend/akkaserverless-javascript-sdk'; | ||
import * as grpc from '@grpc/grpc-js'; | ||
|
||
/** | ||
* Type definitions. | ||
* These types have been generated based on your proto source. | ||
* A TypeScript aware editor such as VS Code will be able to leverage them to provide hinting and validation. | ||
* | ||
* DelegatingService; a strongly typed extension of Action derived from your proto source | ||
* @typedef { import("../lib/generated/json/myservice").MyService } MyService | ||
*/ | ||
|
||
/** | ||
* @type MyService | ||
*/ | ||
const action = new Action( | ||
[ | ||
"com/example/json/json_api.proto", | ||
], | ||
"com.example.json.MyService", | ||
{ | ||
includeDirs: ["./proto"] | ||
} | ||
); | ||
|
||
action.commandHandlers = { | ||
async Consume(request) { | ||
console.log(request); | ||
return replies.noReply(); | ||
}, | ||
// tag::produce[] | ||
async Produce(request) { | ||
return replies.message({ // <2> | ||
arbitrary: "json" | ||
}) | ||
} | ||
// end::produce[] | ||
}; | ||
|
||
export default action; | ||
|
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 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 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 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