Last active
July 24, 2020 03:56
-
-
Save sonus21/b884e654585e28d595bc84e53db031b1 to your computer and use it in GitHub Desktop.
Message Sender Methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface RqueueMessageSender { | |
/** | |
* Enqueue a message on given queue without any delay, consume as soon as possible. | |
* | |
* @param queueName on which queue message has to be send | |
* @param message message object it could be any arbitrary object. | |
* @return message was submitted successfully or failed. | |
*/ | |
boolean enqueue(String queueName, Object message); | |
/** | |
* Schedule a message on the given queue with the provided delay. It will be available to consume | |
* as soon as the delay elapse. | |
* | |
* @param queueName on which queue message has to be send | |
* @param message message object it could be any arbitrary object. | |
* @param delayInMilliSecs delay in milli seconds | |
* @return message was submitted successfully or failed. | |
*/ | |
boolean enqueueIn(String queueName, Object message, long delayInMilliSecs); | |
/** | |
* Schedule a message on the given queue with the provided delay. It will be available to consume | |
* as soon as the delay elapse. | |
* | |
* @param queueName on which queue message has to be send | |
* @param message message object it could be any arbitrary object. | |
* @param delay time to wait before it can be executed. | |
* @return message was submitted successfully or failed. | |
*/ | |
default boolean enqueueIn(String queueName, Object message, Duration delay) { | |
return enqueueIn(queueName, message, delay.toMillis()); | |
} | |
/** | |
* Schedule a message on the given queue with the provided delay. It will be available to consume | |
* as soon as the specified delay elapse. | |
* | |
* @param queueName on which queue message has to be send | |
* @param message message object it could be any arbitrary object. | |
* @param delay time to wait before it can be executed. | |
* @param unit unit of the delay | |
* @return message was submitted successfully or failed. | |
*/ | |
default boolean enqueueIn(String queueName, Object message, long delay, TimeUnit unit) { | |
return enqueueIn(queueName, message, unit.toMillis(delay)); | |
} | |
/** | |
* Schedule a message on the given queue at the provided time. It will be available to consume as | |
* soon as the given time is reached. | |
* | |
* @param queueName on which queue message has to be send | |
* @param message message object it could be any arbitrary object. | |
* @param startTimeInMilliSeconds time at which this message has to be consumed. | |
* @return message was submitted successfully or failed. | |
*/ | |
default boolean enqueueAt(String queueName, Object message, long startTimeInMilliSeconds) { | |
return enqueueIn(queueName, message, startTimeInMilliSeconds - System.currentTimeMillis()); | |
} | |
/** | |
* Schedule a message on the given queue at the provided time. It will be available to consume as | |
* soon as the given time is reached. | |
* | |
* @param queueName on which queue message has to be send | |
* @param message message object it could be any arbitrary object. | |
* @param starTime time at which this message has to be consumed. | |
* @return message was submitted successfully or failed. | |
*/ | |
default boolean enqueueAt(String queueName, Object message, Instant starTime) { | |
return enqueueAt(queueName, message, starTime.toEpochMilli()); | |
} | |
/** | |
* Schedule a message on the given queue at the provided time. It will be available to consume as | |
* soon as the given time is reached. | |
* | |
* @param queueName on which queue message has to be send | |
* @param message message object it could be any arbitrary object. | |
* @param starTime time at which this message has to be consumed. | |
* @return message was submitted successfully or failed. | |
*/ | |
default boolean enqueueAt(String queueName, Object message, Date starTime) { | |
return enqueueAt(queueName, message, starTime.toInstant()); | |
} | |
/** | |
* Enqueue a message on the given queue with the given retry count. This message would not be | |
* consumed more than the specified time due to failure in underlying systems. | |
* | |
* @param queueName on which queue message has to be send | |
* @param message message object it could be any arbitrary object. | |
* @param retryCount how many times a message would be retried, before it can be discarded or send | |
* to dead letter queue configured using {@link RqueueListener#numRetries()} | |
* @return message was submitted successfully or failed. | |
*/ | |
boolean enqueueWithRetry(String queueName, Object message, int retryCount); | |
/** | |
* Enqueue a task that would be scheduled to run in the specified milli seconds. | |
* | |
* @param queueName on which queue message has to be send | |
* @param message message object it could be any arbitrary object. | |
* @param retryCount how many times a message would be retried, before it can be discarded or sent | |
* to dead letter queue configured using {@link RqueueListener#numRetries()} ()} | |
* @param delayInMilliSecs delay in milli seconds, this message would be only visible to the | |
* listener when number of millisecond has elapsed. | |
* @return message was submitted successfully or failed. | |
*/ | |
boolean enqueueInWithRetry( | |
String queueName, Object message, int retryCount, long delayInMilliSecs); | |
/** | |
* Enqueue a message on given queue, that will be consumed as soon as possible. | |
* | |
* @param queueName on which queue message has to be send | |
* @param priority the priority name for this message | |
* @param message message object it could be any arbitrary object. | |
* @return message was submitted successfully or failed. | |
*/ | |
boolean enqueueWithPriority(String queueName, String priority, Object message); | |
/** | |
* Schedule a message on the given queue at the provided time. It will be executed as soon as the | |
* given delay is elapse. | |
* | |
* @param queueName on which queue message has to be send | |
* @param priority the name of the priority level | |
* @param message message object it could be any arbitrary object. | |
* @param delayInMilliSecs delay in milli seconds | |
* @return message was submitted successfully or failed. | |
*/ | |
boolean enqueueInWithPriority( | |
String queueName, String priority, Object message, long delayInMilliSecs); | |
/** | |
* Schedule a message on the given queue at the provided time. It will be executed as soon as the | |
* given delay is elapse. | |
* | |
* @param queueName on which queue message has to be send | |
* @param priority the name of the priority level | |
* @param message message object it could be any arbitrary object. | |
* @param delay time to wait before it can be consumed. | |
* @return message was submitted successfully or failed. | |
*/ | |
default boolean enqueueInWithPriority( | |
String queueName, String priority, Object message, Duration delay) { | |
return enqueueInWithPriority(queueName, priority, message, delay.toMillis()); | |
} | |
/** | |
* Schedule a message on the given queue at the provided time. It will be executed as soon as the | |
* given delay is elapse. | |
* | |
* @param queueName on which queue message has to be send | |
* @param priority the name of the priority level | |
* @param message message object it could be any arbitrary object. | |
* @param delay time to wait before it can be consumed. | |
* @param unit unit of the delay | |
* @return message was submitted successfully or failed. | |
*/ | |
default boolean enqueueInWithPriority( | |
String queueName, String priority, Object message, long delay, TimeUnit unit) { | |
return enqueueInWithPriority(queueName, priority, message, unit.toMillis(delay)); | |
} | |
/** | |
* Schedule a message on the given queue at the provided time. It will be executed as soon as the | |
* given time is reached, time must be in the future. | |
* | |
* @param queueName on which queue message has to be send | |
* @param priority the name of the priority level | |
* @param message message object it could be any arbitrary object. | |
* @param startTimeInMilliSecond time at which the message would be consumed. | |
* @return message was submitted successfully or failed. | |
*/ | |
default boolean enqueueAtWithPriority( | |
String queueName, String priority, Object message, long startTimeInMilliSecond) { | |
return enqueueInWithPriority( | |
queueName, priority, message, startTimeInMilliSecond - System.currentTimeMillis()); | |
} | |
/** | |
* Schedule a message on the given queue at the provided time. It will be executed as soon as the | |
* given time is reached, time must be in the future. | |
* | |
* @param queueName on which queue message has to be send | |
* @param priority the name of the priority level | |
* @param message message object it could be any arbitrary object. | |
* @param startTime time at which message is supposed to consume | |
* @return message was submitted successfully or failed. | |
*/ | |
default boolean enqueueAtWithPriority( | |
String queueName, String priority, Object message, Instant startTime) { | |
return enqueueAtWithPriority(queueName, priority, message, startTime.toEpochMilli()); | |
} | |
/** | |
* Schedule a message on the given queue at the provided time. It will be executed as soon as the | |
* given time is reached, time must be in the future. | |
* | |
* @param queueName on which queue message has to be send | |
* @param priority the name of the priority level | |
* @param message message object it could be any arbitrary object. | |
* @param startTime time at which message would be consumed. | |
* @return message was submitted successfully or failed. | |
*/ | |
default boolean enqueueAtWithPriority( | |
String queueName, String priority, Object message, Date startTime) { | |
return enqueueAtWithPriority(queueName, priority, message, startTime.toInstant()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment