Skip to content

Govind-Upadhyay-12/Message_Queue_npm_package

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

A message queue is a form of communication between different software components or systems. It is widely used in distributed systems to enable asynchronous communication and decouple different parts of a system. The basic idea is to allow one part of a system to send a message to another part without requiring the sender to wait for an immediate response.

To Install the dependency

npm i lionqueue

Features of Message Queue

getDataStructure()

Description: Returns the current data structure of the message queue ('queue' or 'stack').

Parameters: None.

Returns: A string representing the current data structure.

registerProvider(serviceName, callback)

Description: Registers a message provider for a specific service.

Parameters:

  • serviceName (string): The name of the service.
  • callback (function): The callback function to be executed when messages are provided by the service.

unregisterProvider(serviceName)

Description: Unregisters a message provider for a specific service.

Parameters:

  • serviceName (string): The name of the service to unregister.

registerConsumer(serviceName, topic, callback)

Description: Registers a message consumer for a specific service and topic.

Parameters:

  • serviceName (string): The name of the service.
  • topic (string): The topic for which the consumer is registered.
  • callback (function): The callback function to be executed when messages are available for the service and topic.

unregisterConsumer(serviceName, topic, callback)

Description: Unregisters a message consumer for a specific service and topic.

Parameters:

  • serviceName (string): The name of the service.
  • topic (string): The topic for which the consumer is unregistered.
  • callback (function): The callback function to be unregistered.

addMessage(topic, message, priority = 0)

Description: Adds a new message to the message queue or stack.

Parameters:

  • topic (string): The topic to which the message belongs.
  • message (any): The content of the message.
  • priority (number, optional): The priority of the message (default is 0).

sortQueueByPriority()

Description: Sorts the messages in the queue based on their priority.

trimDataStructure()

Description: Trims the size of the message queue or stack to meet the specified maximum size.

acknowledgeMessage(messageId)

Description: Acknowledges and removes a message from the message queue or stack based on its ID.

Parameters:

  • messageId (string): The ID of the message to be acknowledged.

Returns: A string indicating the acknowledgment result.

dequeueMessages()

Description: Dequeues and returns messages from the message queue or stack.

Returns: An array of messages that have been dequeued.

startDequeueProcess()

Description: Starts the automatic dequeue process at a specified interval. Stops automatically if the queue is empty.

Note: Adjust the interval as needed based on your application's requirements.

generateUniqueMessageId()

Description: Generates a unique message ID using the uuid library.

Returns: A unique message ID.

Code Implementation

ray-so-export

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published