Skip to content

How to Define Exchange, Exchange Type, Routing Key, and Bind Exchange to Queue in receiveEndpoint Using masstransit-rabbitmq? #15

@nikita-vedre

Description

@nikita-vedre

I want to define an Exchange, specify its type (e.g., direct, topic, etc.), configure a Routing Key, and bind the Exchange to a Queue in receiveEndpoint. Below is my current JavaScript/TypeScript code using the masstransit-rabbitmq library:

import { MessageRequest, MessageResponse } from './messages';
import { MessageType } from 'masstransit-rabbitmq/dist/messageType';
import masstransit from 'masstransit-rabbitmq';

MessageType.setDefaultNamespace('RabbitMQ_Web_API_Demo.Models');

const bus = masstransit();

bus.receiveEndpoint('request_queue', cfg => {
    cfg.handle<MessageRequest>(new MessageType('MessageRequest'), async context => {
        console.log('Received request :', context.message.requestMessage);

        // Responding with the MessageRequest
        await context.respond<MessageResponse>(
            { responseMessage: context.message.requestMessage + " Successful "}, // Sample response
            send => {
                send.messageType = new MessageType('MessageResponse').toMessageType();
            }
        );

        console.log('Response sent :', context.message.requestMessage);
    });
});

In the .NET implementation using the MassTransit.RabbitMQ library, I can configure an Exchange and bind it to a Queue like this:


cfg.ReceiveEndpoint("request_queue", endpointConfigurator =>
{
    endpointConfigurator.ConfigureConsumeTopology = false;
    endpointConfigurator.Bind<MessageRequest>(x =>
    {
        x.ExchangeType = ExchangeType.Direct;
        x.RoutingKey = builder.Configuration["MassTransit:NodeServiceRouteFilter"];
    });

    endpointConfigurator.ConfigureConsumer<ResponseConsumer>(context); // Configure response consumer
});

Could you guide me on how to achieve the same configuration for Exchange, Exchange type, Routing Key, and Queue binding in the masstransit-rabbitmq library for Node.js/TypeScript?

Any examples, documentation references, or tips would be greatly appreciated!

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