Class AmqplibAxiosAdapterManager

A class used to generate adapters for use with axios based on amqplib-oop

Example

import { AmqplibAxiosAdapterManager } from '@jakguru/amqplib-oop-axios'

or

const { AmqplibAxiosAdapterManager } = require('@jakguru/amqplib-oop-axios')

Retreiving the Adapter

In order to ensure that the script doesn't hang unexpectedly, if the adapter is initialized with ConnectionConstructorOptions, the connection will be closed once the request is complete and the adapter cannot be re-used. In order to create a reusable adapter instance, you should initialize the adapter with an already initialized Connection instance.

Note: If you initialize the adapter with an already initialized Connection instance, you will need to manually close the connection when you are done with it.

Using a single-use adapter with a single-use request

axios({
method: 'post',
url: '/user/12345', // The full domain / URL is not needed because baseUrl is set on the worker
data: {
firstName: 'Fred',
lastName: 'Flintstone'
},
adapter: AmqplibAxiosAdapterManager.make('example-queue', {
// amqplib connection options
})
}).then((response) => {
// handle response normally
}).catch((error) => {
// handle errors as you see fit
});

Creating a multi-use adapter

import { Connection } from '@jakguru/amqplib-oop'
const connection = new Connection()
const adapter = AmqplibAxiosAdapterManager.make('example-queue', connection)

Using a multi-use adapter with a single-use request

axios({
method: 'post',
url: '/user/12345', // The full domain / URL is not needed because baseUrl is set on the worker
data: {
firstName: 'Fred',
lastName: 'Flintstone'
},
adapter,
}).then((response) => {
// handle response normally
}).catch((error) => {
// handle errors as you see fit
});

Using a multi-use adapter with a multi-use axios instance

const instance = axios.create({
adapter,
})

instance({
method: 'post',
url: '/user/12345', // The full domain / URL is not needed because baseUrl is set on the worker
data: {
firstName: 'Fred',
lastName: 'Flintstone'
},
}).then((response) => {
// handle response normally
}).catch((error) => {
// handle errors as you see fit
});

Hierarchy

  • AmqplibAxiosAdapterManager

Constructors

Accessors

Methods

Constructors

Accessors

Methods

  • Close the connection

    Returns Promise<void>

  • Generate an adapter function to be used with the Axios Request Config adapter property

    Parameters

    Returns AxiosAdapter

    The adapter function to be used with the Axios Request Config adapter property

    Note

    If a connection is passed in, it will not be closed when the adapter is closed