Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PubSub with large message does not trigger subscriber #562

Closed
brunoshine opened this issue Dec 14, 2023 · 7 comments
Closed

PubSub with large message does not trigger subscriber #562

brunoshine opened this issue Dec 14, 2023 · 7 comments
Assignees
Labels
bug Something isn't working stale
Milestone

Comments

@brunoshine
Copy link

Expected Behavior

Publishing a large message that, for instance, has a base64 image string should trigger the subscriber.

Publisher

import { DaprClient, CommunicationProtocolEnum } from '@dapr/dapr';
import * as image from './image.js'

const client = new DaprClient({
    communicationProtocol: CommunicationProtocolEnum.GRPC,
    maxBodySizeMb: 10,
});

console.log("Publishing...")
setInterval(async () => {
    await client.pubsub.publish("pubsub", "test", {
        payload: image.data.image, //base64 image string

    }, {
        metadata:{
            ttlInSeconds:"1"
        }
    });
    console.log("published")
}, 3000);

Subscriber:

import { DaprServer, CommunicationProtocolEnum, DaprPubSubStatusEnum } from '@dapr/dapr';
const server = new DaprServer({
    communicationProtocol: CommunicationProtocolEnum.GRPC,
    clientOptions: {
        communicationProtocol: CommunicationProtocolEnum.GRPC
    }
});

const configs = await server.client.configuration.get("configuration", ["key"])

server.pubsub.subscribe("pubsub", "test", async (data, headers) => {
    console.log("Subscriber received: " + JSON.stringify(data));
    return DaprPubSubStatusEnum.SUCCESS;
}
);

await server.start();

command:

"scripts": {
    "client": "dapr run --app-id checkout --dapr-http-port 3502   --app-protocol grpc --resources-path .dapr/components/ -- node client.js",
    "server": "dapr run --app-id order-processing --app-port 5002 --dapr-http-port 3501   --app-protocol grpc --resources-path .dapr/components/ -- node server.js"
  },

Redis PubSub Component Definition

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: pubsub
spec:
  type: pubsub.redis
  version: v1
  metadata:
  - name: redisHost
    value: localhost:6379
  - name: redisPassword
    value: ""

Actual Behavior

Although the message get published to Redis stream the subscriber does not get triggered. In this test we are using a base64 image that is around 150kb.

If I just set the payload to payload: "" the subscriber gets triggered.

Steps to Reproduce the Problem

  • Convert an image to a base64 string and pass the string into the payload on the publisher.
  • Execute both the client and the server npm scripts.
  • Published messages should be on the redis stream named test.
  • Subscriber is not triggered.
  • Stop both client and server.
  • Update the payload to be empty payload:""
  • Execute both the client and the server npm scripts.
  • Published messages should be on the redis stream named test.
  • Subscriber is triggered.
@brunoshine
Copy link
Author

It seems that this also happens with bindings. I have a MQTT Input binding where I have placed a 132kb image base64 string on the body of message topic, and with this the binding does not get triggered. If I remove the base64 string then the binding gets called.

Any thoughts?

thanks

@shubham1172 shubham1172 self-assigned this Jan 2, 2024
@shubham1172 shubham1172 added this to the Dapr Node.js SDK - v3.3.0 milestone Jan 2, 2024
@shubham1172 shubham1172 added the bug Something isn't working label Jan 2, 2024
@shubham1172
Copy link
Member

shubham1172 commented Feb 29, 2024

I am able to reproduce this locally. Tried with both gRPC and HTTP. The message does gets published, and even comes to Dapr (as part of debug logs):

DEBU[0009] Processing Redis message 1709193127018-0      app_id=subscriber component="pubsub (pubsub.redis/v1)" instance=Shubhams-MacBook-Pro-3.local scope=dapr.contrib type=log ver=1.12.5

However, it never reaches the application. I am using a 1MB payload.

  • Increasing the maxBodySizeMb does not work too.
  • I also tried using a Go app like this, it can't receive the large payload either.
  • Then I set to try this with vanilla JavaScript, and it works with the right bodyParser settings
import express from 'express';
import bodyParser from 'body-parser';

const APP_PORT = process.env.APP_PORT ?? '8080';

const app = express();
app.use(bodyParser.json({ type: 'application/*+json', limit: "50mb" }));
// app.use(bodyParser.urlencoded({ limit: "50mb" }));

app.get('/dapr/subscribe', (_req, res) => {
    res.json([
        {
            pubsubname: "pubsub",
            topic: "test",
            route: "/events"
        }
    ]);
});

// Dapr subscription routes orders topic to this route
app.post('/events', (req, res) => {
    console.log("Subscriber received:", req.body.data);
    res.sendStatus(200);
});

app.listen(APP_PORT);

We also have the same configuration in JS-SDK for bodyParser, so this needs further investigation why HTTP (and then also gRPC for some reason) is not working.

@brunoshine
Copy link
Author

Hi @shubham1172 is there any temporary workaround? Thanks

@shubham1172
Copy link
Member

@brunoshine I don't have a workaround for now, but I will further investigate this and update this issue. Thanks for your patience.

@dapr-bot
Copy link
Collaborator

dapr-bot commented May 4, 2024

This issue has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

@dapr-bot dapr-bot added the stale label May 4, 2024
@shubham1172 shubham1172 removed the stale label May 5, 2024
@dapr-bot
Copy link
Collaborator

dapr-bot commented Jul 4, 2024

This issue has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

@dapr-bot dapr-bot added the stale label Jul 4, 2024
@dapr-bot
Copy link
Collaborator

This issue has been automatically closed because it has not had activity in the last 67 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue, help wanted or triaged/resolved. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

4 participants