Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unable to send message to ASB Receiver #422

@suityou01

Description

@suityou01

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions