Skip to content

Commit 7c70ea5

Browse files
authored
Revise sections on keys, timeouts, and queues
1 parent 7ca5121 commit 7c70ea5

1 file changed

Lines changed: 7 additions & 62 deletions

File tree

docs/java-usage-guide.md

Lines changed: 7 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -546,32 +546,13 @@ try {
546546
}
547547
```
548548

549-
### 4. Use Unique, Meaningful Keys
550-
551-
Keys should be:
552-
- **Unique**: Each message needs a distinct identifier
553-
- **Meaningful**: Tied to business entities for debugging and correlation
554-
- **Stable**: Don't change between offer and acknowledgement
555-
556-
Using random UUIDs works but makes debugging harder - you can't easily correlate messages with business entities. Prefer keys that reference your domain objects (order IDs, user IDs, transaction IDs, etc.).
557-
558-
```java
559-
// ✅ Good keys - correlate with business entities
560-
queue.offerOrUpdate("order-" + orderId, payment, deliveryTime);
561-
queue.offerOrUpdate("email-" + userId + "-" + timestamp, email, deliveryTime);
562-
563-
// ❌ Bad keys
564-
queue.offerOrUpdate(UUID.randomUUID().toString(), payment, deliveryTime); // Not meaningful
565-
queue.offerOrUpdate("msg", email, deliveryTime); // Not unique
566-
```
567-
568-
### 5. Configure Appropriate Timeouts
549+
### 4. Configure Appropriate Timeouts
569550

570551
Adjust timeouts based on your processing time:
571552

572553
```java
573-
// Default: 30 second acquire timeout, 100ms poll interval
574-
DelayedQueueTimeConfig defaultConfig = DelayedQueueTimeConfig.DEFAULT;
554+
// Default used for RDBMS access
555+
DelayedQueueTimeConfig defaultConfig = DelayedQueueTimeConfig.DEFAULT_JDBC;
575556

576557
// Custom: 5 minute timeout for long-running tasks
577558
DelayedQueueTimeConfig customConfig = DelayedQueueTimeConfig.create(
@@ -587,39 +568,7 @@ DelayedQueueJDBCConfig config = new DelayedQueueJDBCConfig(
587568
);
588569
```
589570

590-
### 6. Monitor Queue Depth
591-
592-
In production, monitor how many messages are in the queue:
593-
594-
```java
595-
// Check if a specific message exists
596-
boolean exists = queue.containsMessage("payment-12345");
597-
598-
// For monitoring, you can query the database directly
599-
// (assuming table name is "delayed_queue")
600-
String sql = "SELECT COUNT(*) FROM delayed_queue WHERE partition_kind = ?";
601-
```
602-
603-
### 7. Use Connection Pooling for Production
604-
605-
For production with multiple workers, configure connection pooling:
606-
607-
```java
608-
JdbcDatabasePoolConfig poolConfig = new JdbcDatabasePoolConfig(
609-
20, // maxPoolSize - adjust based on your worker count
610-
30000 // connectionTimeoutMs
611-
);
612-
613-
JdbcConnectionConfig dbConfig = new JdbcConnectionConfig(
614-
jdbcUrl,
615-
driver,
616-
username,
617-
password,
618-
poolConfig // Enable pooling
619-
);
620-
```
621-
622-
### 8. Separate Queues by Concern
571+
### 5. Separate Queues by Concern
623572

624573
Use different queue names for different types of work:
625574

@@ -635,10 +584,10 @@ DelayedQueue<Payment> paymentQueue = DelayedQueueJDBC.create(
635584
DelayedQueueJDBCConfig.create(dbConfig, "delayed_queue", "payments")
636585
);
637586

638-
// They can share the same table, but are isolated by queue name
587+
// They can share the same table, but are isolated by queue name + message type
639588
```
640589

641-
### 9. Implement Proper Error Handling
590+
### 6. Implement Proper Error Handling
642591

643592
```java
644593
private void processMessage(AckEnvelope<Task> envelope) {
@@ -670,7 +619,7 @@ private void processMessage(AckEnvelope<Task> envelope) {
670619
}
671620
```
672621

673-
### 10. Test with Time
622+
### 7. Test with Mocked Time
674623

675624
Use a custom `Clock` for testing time-dependent behavior:
676625

@@ -703,7 +652,3 @@ assertNull(queue.tryPoll());
703652
- [Javadoc](https://javadoc.io/doc/org.funfix/delayedqueue-jvm)
704653
- [Internals Documentation](./internals.md)
705654
- [GitHub Repository](https://github.com/funfix/database)
706-
707-
## Support
708-
709-
For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/funfix/database).

0 commit comments

Comments
 (0)