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

Unable to send message to ASB Receiver #422

Open
suityou01 opened this issue Jul 2, 2024 · 1 comment
Open

Unable to send message to ASB Receiver #422

suityou01 opened this issue Jul 2, 2024 · 1 comment

Comments

@suityou01
Copy link

I have a server set up using rhea that looks like this using node.js

import rhea from "rhea";
import url from "url";
import fs from "fs";
import path from "path";

const container = rhea.create_container();

const opts = {
    id: "myserver",
    max_frame_size: 512,
    host: "0.0.0.0",
    port: 5671,
    transport: "tls",
    cert: fs.readFileSync(path.join(process.cwd(), 'src/certs/server.crt')),
    key: fs.readFileSync(path.join(process.cwd(), 'src/certs/server.key')),
};

const server = container.listen(opts);

I have set up listeners for the container events as per the examples

container.on('receiver_open', function (context) {
    context.receiver.set_target({address:context.receiver.remote.attach.target.address});
});

container.on('sender_open', function (context) {
    if (context.sender.source.dynamic) {
        var id = container.generate_uuid();
        context.sender.set_source({address:id});
    }
});

I have my receiver set up in another file like this

import{ ServiceBusClient } from "@azure/service-bus";

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

const topicName = "MYTOPIC";
const subscriptionName = "MYSUBSCRIPTION";

const sbClient = new ServiceBusClient(`Endpoint=sb://localhost/;SharedAccessKeyName=charlie;SharedAccessKey=password`);
const receiver = sbClient.createReceiver(topicName, subscriptionName);

const myMessageHandler = async (messageReceived) => {
    console.log(`Received message: ${messageReceived.body}`);
};

const myErrorHandler = async (error) => {
    console.log(error);
};

receiver.subscribe({
    processMessage: myMessageHandler,
    processError: myErrorHandler
});

I have tried to send a message to the receiver in the "sendable" event of the container but don't see it appearing in the receiver's myMessageHandler.

container.on('sendable', function (context) {
    console.log("Sendable");
    context.connection.send({ to: receiverId, body: "Hello World" });
});

I know this may be a vendor specific question but I cannot find any vendor specific answers so I have come here for guidance.

How can I send a message successfully to the receiver from this simple rhea server setup?

@grs
Copy link
Member

grs commented Jul 3, 2024

I'm not totally sure what it is you are trying to do. I also don't know anything about the ServiceBusClient.

As a general point you usually send to the same address that the receiver is receiving from. So in this case that would be the topicName. Of course for a typical broker 'topic', all the subscribers would get that message. Not sure if that is what you want, or if you are trying to communicate with a specific subscriber without using the topic address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants