bbc / sqs-consumer

Build Amazon Simple Queue Service (SQS) based applications without the boilerplate
https://bbc.github.io/sqs-consumer/
Other
1.74k stars 333 forks source link

Storage Queue Integration (Azure) #267

Closed allanclempe closed 1 year ago

allanclempe commented 3 years ago

The problem This library is limited to AWS SQS service whereas other providers are out there. The idea is to expand it to be used for any queue service provider, starting with Storage Queue Service (Azure).

Suggested solution Abstract queue methods and create different implementation for each provider (AWS and Azure) preserving the core functionality.

interface IQueueProvider {
  receiveMessage(options?: ReceiveMessageOptions): Promise<ReceiveMessageResult>;
  deleteMessage(message: MessageIdentification): Promise<void>;
  deleteMessageBatch(messages: MessageIdentification[]): Promise<void>;
  changeMessageVisibility(message: MessageIdentification, timeout: number): Promise<void>;
  changeMessageVisibilityBatch(messages: MessageIdentification[], timeout: number): Promise<void>;
}

interface AwsQueueProvider implements IQueueProvider { }
interface AzureQueueProvider implements IQueueProvider { }

Consumer.create(provider, options);

That way, any impl to IQueueProvider could be passed in to sqs-consumer.

Additional context I have done some work already and have it fully working for Azure. If you guys are interested to have this feature in place, I'm keen to work a bit more on docs and tests (got 70% coverage so far)

Let me know your thoughts.

Thanks

allanclempe commented 3 years ago

quick update: Azure storage queue doesn't support long polling, so I had to take that off from the default configuration People still can use tho, by passing manually to a new prop called receiveOptions which will be injected as additional param. This is how I would setup SQS consumer.

const provider = new AwsQueueProvider("http://queue.url");

Consumer.create(provider, {
  pollingWaitTimeMs: 0,
  receiveOptions: {
    // enabling long pooling for AWS
    WaitTimeSeconds: 30,
  },
  handleMessage: message => {},
});
github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

nicholasgriffintn commented 1 year ago

I don't think we have any plans to support other providers, but thanks for the contribution!