question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

routing with sdk setup always invokes default handler

See original GitHub issue

Expected Behavior

i have followed the docs here and tried to setup message routing with the SDK and expect to invoke different handlers based on the type.

https://docs.dapr.io/developing-applications/sdks/js/js-server/

i had to make some adjustments as the docs seem to be slightly off?

import process from "process";
import { DaprServer } from "@dapr/dapr";

const DAPR_HOST = process.env.DAPR_HOST || "http://localhost";
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 || 5002;

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

const server = new DaprServer(
  SERVER_HOST,
  SERVER_PORT.toString(),
  DAPR_HOST,
  DAPR_HTTP_PORT
);

const PUBSUB_NAME: string = "pubsub";
const PUBSUB_TOPIC: string = "topic-1";
await server.pubsub.subscribeWithOptions(PUBSUB_NAME, PUBSUB_TOPIC, {
  route: {
    default: "/default",
    rules: [
      {
        match: `event.type == "new.event"`,
        path: "/new",
      },
    ],
  },
});

server.pubsub.subscribeToRoute(
  PUBSUB_NAME,
  PUBSUB_TOPIC,
  "default",
  async (data) => {
    console.log(`Handling Default`);
    console.log(JSON.stringify(data));
  }
);

server.pubsub.subscribeToRoute(
  PUBSUB_NAME,
  PUBSUB_TOPIC,
  "new",
  async (data) => {
    console.log(`Handling new event: ${data}`);
  }
);

await server.start();

Actual Behavior

the default is always invoked.

Steps to Reproduce the Problem

you should be able to run this code with the “type”: “module” in your package.json. when you publish a message through the sdk or via the vs code extension the default handler is always invoked.

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dgcaroncommented, Dec 19, 2022

for anyone stumbling upon this too before the new release has been made. i have found the easiest way to send cloud events is with the cloud events package. (https://github.com/cloudevents/sdk-javascript#emitting-events)

// run this at startup
import { Emitter, emitterFor, httpTransport } from "cloudevents";

const emit = emitterFor(httpTransport(`${DAPR_HOST}:${DAPR_HTTP_PORT}/v1.0/publish/pubsub/topic-1`));
Emitter.on("cloudevent", emit);
// then in your application 
let event = new CloudEvent({type: 'new.event', source: '/mycontext', data });
await event.emit();
1reaction
shubham1172commented, Dec 19, 2022

Till the next release, you can point to the GitHub project directly -

npm install --save dapr/js-sdk

See https://docs.npmjs.com/cli/v9/configuring-npm/package-json#github-urls, you can also consider using a commit hash.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invoking your backend integration: $default Route and custom ...
You can set up a route request for a WebSocket API in the API Gateway console, by using the AWS CLI, or by...
Read more >
Routing to controller actions in ASP.NET Core - Microsoft Learn
MapControllerRoute is used to create a single route. The single route is named default route. Most apps with controllers and views use a...
Read more >
Permissions used only in default handlers - Android Developers
The Settings app on Android includes a screen that shows users which apps are currently default handlers for the device's core functions, as ......
Read more >
How do you enforce lowercase routing in ASP.NET Core?
I'd think it would be here: app.UseMvc(configureRoutes => { configureRoutes.MapRoute("Default", "{controller=App}/{action=Index}/{ ...
Read more >
Tune Routing Behavior - Digital Assistant - Oracle Help Center
You can also customize the default welcome prompt using the Skill Bot Welcome Prompt configuration setting. Help State: Applies when the intent engine ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found