Implements: MessageQueue
DescriptionConfigure
The NatsAbstractMessageQueue class allows you to define abstract NATS message queues with the ability to connect to NATS servers.
Constructors
InheritNatsAbstractMessageQueue
Creates a new instance of the component.
InheritNatsAbstractMessageQueue(overrides cqueues.IMessageQueueOverrides, name string, capabilities *MessagingCapabilities) *NatsAbstractMessageQueue
- overrides: cqueues.IMessageQueueOverrides - override
- name: string - (optional) queue name.
- capabilities: *MessagingCapabilities - supported capabilities
Fields
Methods
Abandon
Returns a message into the queue and makes it available for all subscribers to receive it again.
This method is usually used to return a message which could not be processed at the moment,
to repeat the attempt. Messages that cause unrecoverable errors shall be removed
permanently or/and send to the dead letter queue.
- Important: This method is not supported by NATS.
(c *NatsAbstractMessageQueue) Abandon(ctx context.Context, message *MessageEnvelope) (err error)
- ctx: context.Context - operation context.
- message: *MessageEnvelope - message to return.
- returns: (err error) - error or nil if no errors occurred.
Clear
Clears a component’s state.
(c *NatsAbstractMessageQueue) Clear(ctx context.Context, context IContext) error
- ctx: context.Context - operation context.
- context: IContext - (optional) a context to trace execution through a call chain.
- returns: (err error) - error or nil if no errors occurred.
Close
Closes a component and frees the used resources.
(c *NatsAbstractMessageQueue) Close(ctx context.Context, context IContext) (err error)
- ctx: context.Context - operation context.
- context: IContext - (optional) a context to trace execution through a call chain.
- returns: (err error) - error or nil if no errors occurred.
Complete
Permanently removes a message from the queue. This method is usually used to remove the message after successful processing.
- Important: This method is not supported by NATS.
(c *NatsAbstractMessageQueue) Complete(ctx context.Context, message *MessageEnvelope) (err error)
- ctx: context.Context - operation context.
- message: *MessageEnvelope - message to remove.
- returns: (err error) - error or nil no errors occured.
Configure
Configures a component by passing its configuration parameters.
(c *NatsAbstractMessageQueue) Configure(ctx context.Context, config *ConfigParams)
- ctx: context.Context - operation context.
- config:: *ConfigParams - configuration parameters to be set.
FromMessage
Returns the headers and data from a message.
(c *NatsAbstractMessageQueue) FromMessage(message *MessageEnvelope) (*nats.Msg, error)
- message: *MessageEnvelope - message
- returns: (*nats.Msg, error) - message headers and data.
IsOpen
Checks if the component is open.
(c *NatsAbstractMessageQueue) IsOpen() bool
- returns: bool - true if the component is open and false otherwise.
MoveToDeadLetter
Permanently removes a message from the queue and sends it to the dead letter queue.
- Important: This method is not supported by NATS.
(c *NatsAbstractMessageQueue) MoveToDeadLetter(ctx context.Context, message *cqueues.MessageEnvelope) (err error)
- ctx: context.Context - operation context.
- message: MessageEnvelope - message to be removed.
- returns: (err error) - error or nil if no errors occurred.
Open
Opens the component.
(c *NatsAbstractMessageQueue) Open(ctx context.Context, context IContext) (err error)
- ctx: context.Context - operation context.
- context: IContext - (optional) a context to trace execution through a call chain.
- returns: (err error) - error or nil if no errors occurred.
OpenWithParams
OpenWithParams method are opens the component with given connection and credential parameters.
c *NatsAbstractMessageQueue) OpenWithParams(ctx context.Context, context IContext, connections []*ConnectionParams, credential *CredentialParams)
- ctx: context.Context - operation context
- context: IContext - (optional) a context to trace execution through a call chain.
- connections: []*ConnectionParams - connection parameters
- credential: *CredentialParams - credential parameters
ReadMessageCount
Reads the current number of messages in the queue to be delivered.
(c *NatsAbstractMessageQueue) ReadMessageCount() (int64, error)
- *returns: (int64, error) - number of messages in the queue.
RenewLock
Renews a lock on a message that makes it invisible from other receivers in the queue. This method is usually used to extend the message processing time.
- Important: This method is not supported by NATS.
(c *NatsAbstractMessageQueue) RenewLock(ctx context.Context, message *MessageEnvelope, lockTimeout time.Duration) (err error)
- ctx: context.Context - operation context.
- message: *MessageEnvelope - message to extend its lock.
- lockTimeout: time.Duration - locking timeout in milliseconds.
- returns: (err error) - error or nil if no errors occurred.
Send
Sends a message into the queue.
(c *NatsAbstractMessageQueue) Send(ctx context.Context, context IContext, envelop *MessageEnvelope) error
- ctx: context.Context - operation context.
- context: IContext - (optional) a context to trace execution through a call chain.
- message: *MessageEnvelope - message envelop to be sent.
- returns: error - error or nil if no errors occurred.
SetReferences
Sets references to dependent components.
(c *NatsAbstractMessageQueue) SetReferences(ctx context.Context, references IReferences)
- ctx context.Context - operation context.
- references: IReferences - references to locate the component’s dependencies.
ToMessage
If the message is nil, it returns nil. Otherwise, it returns the message.
(c *NatsAbstractMessageQueue) ToMessage(msg *nats.Msg) (*MessageEnvelope, error)
- msg: *nats.Msg - message
- returns: (*MessageEnvelope, error) - message
UnsetReferences
Unsets (clears) previously set references to dependent components.
(c *NatsAbstractMessageQueue) UnsetReferences()