dapr / dapr/js-sdk

Subscribe is not working if daprServer.start() is invoked

Open
#717 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
217
Forks
104
PR merge metrics
No merged PRs in 30d

Description

## Expected Behavior

Subscribe made before daprServer.start()

## Actual Behavior

Subscribe after before daprServer.start()

## Steps to Reproduce the Problem

```
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DaprServer } from '@dapr/dapr';
import * as express from 'express';
import { ExpressAdapter } from '@nestjs/platform-express';

async function bootstrap() {
const port = '3002';
const server = express();

const pubsubName = 'pubsub-name';

// I'using JetStream as queue
const topic1 = 'xxx.>';
const topic2 = 'yyy.>';

server.use((req, res, next) => {
if (req.path.startsWith('/dapr') || req.path.startsWith('/events/'))
return next();
return next();
});

const daprServer = new DaprServer({
serverHost: 'localhost',
serverPort: port,
serverHttp: server,
clientOptions: {
daprHost: 'localhost',
daprPort: '3502',
},
});

await daprServer.pubsub.subscribe(
pubsubName,
topic1,
async (data) => console.log(topic1),
undefined,
{ rawPayload: true },
);

await daprServer.start();

await daprServer.pubsub.subscribe(
pubsubName,
topic2,
async (data) => console.log(topic2),
undefined,
{ rawPayload: true },
);

const app = await NestFactory.create(AppModule, new ExpressAdapter(server));
await app.init();
}
bootstrap();
```

## Proposed fix
Fix server subscribe documentation and move subscribe before `daprSever.start()`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.