mirror of https://github.com/dapr/docs.git
Update javascript snippets
Signed-off-by: Wralith <wralithdev@gmail.com>
This commit is contained in:
parent
a9ffe331df
commit
401ff35e94
|
@ -270,7 +270,11 @@ const daprHost = "127.0.0.1";
|
|||
async function sendOrder(orderId) {
|
||||
const BINDING_NAME = "checkout";
|
||||
const BINDING_OPERATION = "create";
|
||||
const client = new DaprClient(daprHost, process.env.DAPR_HTTP_PORT, CommunicationProtocolEnum.HTTP);
|
||||
const client = new DaprClient({
|
||||
daprHost,
|
||||
daprPort: process.env.DAPR_HTTP_PORT,
|
||||
communicationProtocol: CommunicationProtocolEnum.HTTP,
|
||||
});
|
||||
//Using Dapr SDK to invoke output binding
|
||||
const result = await client.binding.send(BINDING_NAME, BINDING_OPERATION, orderId);
|
||||
console.log("Sending message: " + orderId);
|
||||
|
|
|
@ -237,7 +237,15 @@ start().catch((e) => {
|
|||
});
|
||||
|
||||
async function start() {
|
||||
const server = new DaprServer(serverHost, serverPort, daprHost, daprPort, CommunicationProtocolEnum.HTTP);
|
||||
const server = new DaprServer({
|
||||
serverHost,
|
||||
serverPort,
|
||||
communicationProtocol: CommunicationProtocolEnum.HTTP,
|
||||
clientOptions: {
|
||||
daprHost,
|
||||
daprPort,
|
||||
}
|
||||
});
|
||||
await server.binding.receive('checkout', async (orderId) => console.log(`Received Message: ${JSON.stringify(orderId)}`));
|
||||
await server.startServer();
|
||||
}
|
||||
|
|
|
@ -355,13 +355,15 @@ start().catch((e) => {
|
|||
});
|
||||
|
||||
async function start(orderId) {
|
||||
const server = new DaprServer(
|
||||
serverHost,
|
||||
serverPort,
|
||||
daprHost,
|
||||
process.env.DAPR_HTTP_PORT,
|
||||
CommunicationProtocolEnum.HTTP
|
||||
);
|
||||
const server = new DaprServer({
|
||||
serverHost,
|
||||
serverPort,
|
||||
communicationProtocol: CommunicationProtocolEnum.HTTP,
|
||||
clientOptions: {
|
||||
daprHost,
|
||||
daprPort: process.env.DAPR_HTTP_PORT,
|
||||
},
|
||||
});
|
||||
//Subscribe to a topic
|
||||
await server.pubsub.subscribe("order-pub-sub", "orders", async (orderId) => {
|
||||
console.log(`Subscriber received: ${JSON.stringify(orderId)}`)
|
||||
|
@ -625,7 +627,11 @@ var main = function() {
|
|||
async function start(orderId) {
|
||||
const PUBSUB_NAME = "order-pub-sub"
|
||||
const TOPIC_NAME = "orders"
|
||||
const client = new DaprClient(daprHost, process.env.DAPR_HTTP_PORT, CommunicationProtocolEnum.HTTP);
|
||||
const client = new DaprClient({
|
||||
daprHost,
|
||||
daprPort: process.env.DAPR_HTTP_PORT,
|
||||
communicationProtocol: CommunicationProtocolEnum.HTTP
|
||||
});
|
||||
console.log("Published data:" + orderId)
|
||||
//Using Dapr SDK to publish a topic
|
||||
await client.pubsub.publish(PUBSUB_NAME, TOPIC_NAME, orderId);
|
||||
|
|
|
@ -387,13 +387,20 @@ import { DaprServer } from "@dapr/dapr";
|
|||
const pubSubName = "orderPubSub";
|
||||
const topic = "topicbulk";
|
||||
|
||||
const DAPR_HOST = process.env.DAPR_HOST || "127.0.0.1";
|
||||
const DAPR_HTTP_PORT = process.env.DAPR_HTTP_PORT || "3502";
|
||||
const SERVER_HOST = process.env.SERVER_HOST || "127.0.0.1";
|
||||
const SERVER_PORT = process.env.APP_PORT || 5001;
|
||||
const daprHost = process.env.DAPR_HOST || "127.0.0.1";
|
||||
const daprPort = process.env.DAPR_HTTP_PORT || "3502";
|
||||
const serverHost = process.env.SERVER_HOST || "127.0.0.1";
|
||||
const serverPort = process.env.APP_PORT || 5001;
|
||||
|
||||
async function start() {
|
||||
const server = new DaprServer(SERVER_HOST, SERVER_PORT, DAPR_HOST, DAPR_HTTP_PORT);
|
||||
const server = new DaprServer({
|
||||
serverHost,
|
||||
serverPort,
|
||||
clientOptions: {
|
||||
daprHost,
|
||||
daprPort,
|
||||
},
|
||||
});
|
||||
|
||||
// Publish multiple messages to a topic with default config.
|
||||
await client.pubsub.bulkSubscribeWithDefaultConfig(pubSubName, topic, (data) => console.log("Subscriber received: " + JSON.stringify(data)));
|
||||
|
|
|
@ -218,7 +218,11 @@ import { DaprClient, HttpMethod, CommunicationProtocolEnum } from '@dapr/dapr';
|
|||
const daprHost = "127.0.0.1";
|
||||
|
||||
async function main() {
|
||||
const client = new DaprClient(daprHost, process.env.DAPR_HTTP_PORT, CommunicationProtocolEnum.HTTP);
|
||||
const client = new DaprClient({
|
||||
daprHost,
|
||||
daprPort: process.env.DAPR_HTTP_PORT,
|
||||
communicationProtocol: CommunicationProtocolEnum.HTTP,
|
||||
});
|
||||
const SECRET_STORE_NAME = "localsecretstore";
|
||||
//Using Dapr SDK to get a secret
|
||||
var secret = await client.secret.get(SECRET_STORE_NAME, "secret");
|
||||
|
|
|
@ -347,7 +347,12 @@ var main = function() {
|
|||
}
|
||||
|
||||
async function start(orderId) {
|
||||
const client = new DaprClient(daprHost, process.env.DAPR_HTTP_PORT, CommunicationProtocolEnum.HTTP);
|
||||
const client = new DaprClient({
|
||||
daprHost: daprHost,
|
||||
daprPort: process.env.DAPR_HTTP_PORT,
|
||||
communicationProtocol: CommunicationProtocolEnum.HTTP
|
||||
});
|
||||
|
||||
//Using Dapr SDK to invoke a method
|
||||
const result = await client.invoker.invoke('checkoutservice' , "checkout/" + orderId , HttpMethod.GET);
|
||||
console.log("Order requested: " + orderId);
|
||||
|
|
|
@ -266,7 +266,11 @@ var main = function() {
|
|||
}
|
||||
|
||||
async function start(orderId) {
|
||||
const client = new DaprClient(daprHost, process.env.DAPR_HTTP_PORT, CommunicationProtocolEnum.HTTP);
|
||||
const client = new DaprClient({
|
||||
daprHost,
|
||||
daprPort: process.env.DAPR_HTTP_PORT,
|
||||
communicationProtocol: CommunicationProtocolEnum.HTTP,
|
||||
});
|
||||
const STATE_STORE_NAME = "statestore";
|
||||
//Using Dapr SDK to save and get state
|
||||
await client.state.save(STATE_STORE_NAME, [
|
||||
|
@ -483,7 +487,12 @@ const daprHost = "127.0.0.1";
|
|||
var main = function() {
|
||||
const STATE_STORE_NAME = "statestore";
|
||||
//Using Dapr SDK to save and get state
|
||||
const client = new DaprClient(daprHost, process.env.DAPR_HTTP_PORT, CommunicationProtocolEnum.HTTP);
|
||||
const client = new DaprClient({
|
||||
daprHost,
|
||||
daprPort: process.env.DAPR_HTTP_PORT,
|
||||
communicationProtocol: CommunicationProtocolEnum.HTTP,
|
||||
});
|
||||
|
||||
await client.state.delete(STATE_STORE_NAME, "order_1");
|
||||
}
|
||||
|
||||
|
@ -630,7 +639,12 @@ var main = function() {
|
|||
const STATE_STORE_NAME = "statestore";
|
||||
var orderId = 100;
|
||||
//Using Dapr SDK to save and retrieve multiple states
|
||||
const client = new DaprClient(daprHost, process.env.DAPR_HTTP_PORT, CommunicationProtocolEnum.HTTP);
|
||||
const client = new DaprClient({
|
||||
daprHost,
|
||||
daprPort: process.env.DAPR_HTTP_PORT,
|
||||
communicationProtocol: CommunicationProtocolEnum.HTTP,
|
||||
});
|
||||
|
||||
await client.state.save(STATE_STORE_NAME, [
|
||||
{
|
||||
key: "order_1",
|
||||
|
@ -870,7 +884,12 @@ var main = function() {
|
|||
}
|
||||
|
||||
async function start(orderId) {
|
||||
const client = new DaprClient(daprHost, process.env.DAPR_HTTP_PORT, CommunicationProtocolEnum.HTTP);
|
||||
const client = new DaprClient({
|
||||
daprHost,
|
||||
daprPort: process.env.DAPR_HTTP_PORT,
|
||||
communicationProtocol: CommunicationProtocolEnum.HTTP,
|
||||
});
|
||||
|
||||
const STATE_STORE_NAME = "statestore";
|
||||
//Using Dapr SDK to save and retrieve multiple states
|
||||
await client.state.transaction(STATE_STORE_NAME, [
|
||||
|
|
Loading…
Reference in New Issue