ISQSQueuePoller
Interface in AWS.SQS
Queue poller interface. See TSQSQueuePoller for implementation.
Properties
AttributeNames
property AttributeNames: TList<string>
List of message attribute names to return along with each message. Valid values: All | Policy | VisibilityTimeout | MaximumMessageSize | MessageRetentionPeriod | ApproximateNumberOfMessages | ApproximateNumberOfMessagesNotVisible | CreatedTimestamp | LastModifiedTimestamp | QueueArn | ApproximateNumberOfMessagesDelayed | DelaySeconds | ReceiveMessageWaitTimeSeconds | RedrivePolicy | FifoQueue | ContentBasedDeduplication | KmsMasterKeyId | KmsDataKeyReusePeriodSeconds | DeduplicationScope | FifoThroughputLimit | RedriveAllowPolicy
IdleTimeout
property IdleTimeout: TOptional<Integer>
An optional IdleTimeout value for Poll operations specified in milliseconds.
MaxNumberOfMessages
property MaxNumberOfMessages: TOptional<Integer>
Optional value for specifying maximum number of messages to retrieve in a single Poll batch. Valid values range from 1 to 10. When not specified the default number of messages requested is 1.
MessageAttributeNames
property MessageAttributeNames: TList<string>
Specifies a list of message attributes by name to be returned along with each message. Specifying All or .* will return all message attributes.
OnBeforeRequest
property OnBeforeRequest: TSQSQueuePollerBeforeRequestHandler
Optionally specify an OnBeforeRequest to receive a callback before each Poll request is started. The handler method is provided with polling statistics.
var QueueUrl := 'https://...'; var Poller := TSQSQueuePoller.Create(QueueUrl) as ISQSQueuePoller; Poller.OnBeforeRequest := procedure(const APoller: ISQSQueuePoller; const AStats: TSQSQueuePollerStatistics) begin if AStats.RequestCount = 0 then Log(Format('Polling started at %s', [FormatDateTime('c', AStats.PollingStartedAt)])) else Log(Format('Polling iteration %d', [AStats.RequestCount])); Log(Format('Messages received to date %d', [AStats.ReceivedMessageCount])); end; )
SkipDelete
property SkipDelete: Boolean
Property defining behaviour at end of each polling loop cycle. By default this property is set to false and messages will be automatically deleted at the end of the Poll procedure. When setting this property to true, use DeleteMessage or DeleteMessages to remove messages you have successfully processed.
VisibilityTimeout
property VisibilityTimeout: TOptional<Integer>
Optionally specify VisibilityTimeout to set the amount of time in seconds you have to process each received message before it is returned to the queue.
WaitTimeSeconds
property WaitTimeSeconds: TOptional<Integer>
Optionally specify the long poll interval in seconds. Messages are yielded as soon as they are received. The WaitTimeSeconds specifies the maximum period of time to wait on each polling attempt before starting a new poll attempt. The default value is 20 seconds if not specified.
Methods
ChangeMessageVisibilityTimeout
procedure ChangeMessageVisibilityTimeout(const AMessage: ISQSMessage; const ATimeout: Integer);
Changes the message visibility timeout for a given message.
This should be called within a Poll procedure block.
var QueueUrl := 'https://...'; var Poller = TSQSQueuePoller.Create(QueueUrl) as ISQSQueuePoller; Poller.Poll( procedure(const AMessages: TSQSMessages) begin for var LMessage in AMessages do begin // If you need more time to process the message, // change it's visibility timeout. Poller.ChangeMessageVisibilityTimeout(LMessage, 900); end; end ); )
Parameters
| Name | Description |
|---|---|
AMessage | Specify the message. |
ATimeout | New timeout value in seconds. Valid values range from 0 to 43200 (12 hours). |
DeleteMessage
procedure DeleteMessage(const AMessage: ISQSMessage);
Deletes the specified message.
Use this in conjunction with SkipDelete to control which messages are deleted during processing. This should be called within a Poll procedure block.
var QueueUrl := 'https://...'; var Poller = TSQSQueuePoller.Create(QueueUrl) as ISQSQueuePoller; Poller.SkipDelete := True; Poller.Poll( procedure(const AMessages: TSQSMessages) begin for var LMessage in AMessages do begin // Process the message then delete it when you're done. Poller.DeleteMessage(LMessage); end; end ); )
Parameters
| Name | Description |
|---|---|
AMessage | Specify the message to delete. |
DeleteMessages
procedure DeleteMessages(const AMessages: TSQSMessages);
Deletes the specified list of messages.
Use this in conjunction with SkipDelete to control which messages are deleted during processing. This should be called within a Poll procedure block.
NOTE: The behaviour of this example is the same as leaving SkipDelete unchanged (false). <code lang="delphi"> var QueueUrl := 'https://...'; var Poller = TSQSQueuePoller.Create(QueueUrl) as ISQSQueuePoller; Poller.SkipDelete := True; Poller.Poll( procedure(const AMessages: TSQSMessages) begin for var LMessage in AMessages do begin // Process the message. end; // Delete the messages. Poller.DeleteMessages(AMessages); end ); )
Parameters
| Name | Description |
|---|---|
AMessages | Specify a list of messages to delete. |
Poll
procedure Poll(const AHandler: TSQSQueuePollerHandler);
Polls for messages.
Messages are automatically deleted from the queue at the end of the given Poll procedure. Use SkipDelete property to change this behaviour.
var QueueUrl := 'https://...'; var Poller = TSQSQueuePoller.Create(QueueUrl) as ISQSQueuePoller; Poller.Poll( procedure(const AMessages: TSQSMessages) begin // Do something with AMessages. end ); )
Parameters
| Name | Description |
|---|---|
AHandler | Provide a handler method for processing messages. |
StopPolling
procedure StopPolling;
Stops the polling gracefully.
This should be called within a Poll procedure block.