-
Notifications
You must be signed in to change notification settings - Fork 140
[Doc] Queue Callbacks for QBit queue based services
QBit supports QueueCallback methods to optimize queue throughput and IO throughput.
/**
* Created by rhightower on 2/10/15.
*/
public interface QueueCallBackHandler {
/**
* Queue has reached its limit, can be the same as batch size for queue.
* This is for periodic flushing to IO or CPU intensive services to improve throughput.
* Larger batches can equate to a lot less thread sync for the hand-off.
*/
void queueLimit();
/**
* Notification that there is nothing else in the queue.
*/
void queueEmpty();
/** Callback for when the queue has started. */
default void queueInit() {}
/** Callback for when the queue is idle. */
default void queueIdle() {}
/** Callback for when the queue is shutdown. */
default void queueShutdown(){}
/** Callback for when the queue has just received some message.
* idle can mean you are asleep with nothing to do.
* startBatch can mean you just woke up.
**/
default void queueStartBatch() {}
}
If you implement these methods in your server, QBit will pick them up. It can do this automatically of you can implement this interface, or you can mark your methods with an annotation. You cannot mix. Pick one style. Implement the interface, which ties you to QBit. Or, use an annotation (you can define your own annotation and enum as long as you match the names so you are not tied to QBit) and a enum. Or use the naming convention.
Here is the annotation.
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface QueueCallback {
/* The type of callback. */;
QueueCallbackType value() default QueueCallbackType.DYNAMIC;
}
Example usage:
##Annotation
public class EventManagerImpl implements EventManager {
@QueueCallback(QueueCallbackType.LIMIT)
private void queueLimit() {
if (messageCountSinceLastFlush > 100_000) {
now = Timer.timer().now();
sendMessages();
return;
}
now = Timer.timer().now();
long duration = now - lastFlushTime;
if (duration > 50 && messageCountSinceLastFlush > 0) {
sendMessages();
}
}
@QueueCallback(QueueCallbackType.EMPTY)
private void queueEmpty() {
if (messageCountSinceLastFlush > 100) {
now = Timer.timer().now();
sendMessages();
return;
}
now = Timer.timer().now();
long duration = now - lastFlushTime;
if (duration > 50 && messageCountSinceLastFlush > 0) {
sendMessages();
}
}
##Interface
public class StatService implements QueueCallBackHandler {
public void queueLimit() {
now = Timer.timer().now();
process();
}
public void queueEmpty() {
now = Timer.timer().now();
process();
}
##Convention
@RequestMapping("/myservice")
public class MyServiceQBit {
void queueLimit() {
...
}
void queueEmpty() {
...
}
QBit Website What is Microservices Architecture?
QBit Java Micorservices lib tutorials
The Java microservice lib. QBit is a reactive programming lib for building microservices - JSON, HTTP, WebSocket, and REST. QBit uses reactive programming to build elastic REST, and WebSockets based cloud friendly, web services. SOA evolved for mobile and cloud. ServiceDiscovery, Health, reactive StatService, events, Java idiomatic reactive programming for Microservices.
Reactive Programming, Java Microservices, Rick Hightower
Java Microservices Architecture
[Microservice Service Discovery with Consul] (http://www.mammatustech.com/Microservice-Service-Discovery-with-Consul)
Microservices Service Discovery Tutorial with Consul
[Reactive Microservices] (http://www.mammatustech.com/reactive-microservices)
[High Speed Microservices] (http://www.mammatustech.com/high-speed-microservices)
Reactive Microservices Tutorial, using the Reactor
QBit is mentioned in the Restlet blog
All code is written using JetBrains Idea - the best IDE ever!
Kafka training, Kafka consulting, Cassandra training, Cassandra consulting, Spark training, Spark consulting
Tutorials
- QBit tutorials
- Microservices Intro
- Microservice KPI Monitoring
- Microservice Batteries Included
- RESTful APIs
- QBit and Reakt Promises
- Resourceful REST
- Microservices Reactor
- Working with JSON maps and lists
__
Docs
Getting Started
- First REST Microservice
- REST Microservice Part 2
- ServiceQueue
- ServiceBundle
- ServiceEndpointServer
- REST with URI Params
- Simple Single Page App
Basics
- What is QBit?
- Detailed Overview of QBit
- High level overview
- Low-level HTTP and WebSocket
- Low level WebSocket
- HttpClient
- HTTP Request filter
- HTTP Proxy
- Queues and flushing
- Local Proxies
- ServiceQueue remote and local
- ManagedServiceBuilder, consul, StatsD, Swagger support
- Working with Service Pools
- Callback Builders
- Error Handling
- Health System
- Stats System
- Reactor callback coordination
- Early Service Examples
Concepts
REST
Callbacks and Reactor
Event Bus
Advanced
Integration
- Using QBit in Vert.x
- Reactor-Integrating with Cassandra
- Using QBit with Spring Boot
- SolrJ and service pools
- Swagger support
- MDC Support
- Reactive Streams
- Mesos, Docker, Heroku
- DNS SRV
QBit case studies
QBit 2 Roadmap
-- Related Projects
- QBit Reactive Microservices
- Reakt Reactive Java
- Reakt Guava Bridge
- QBit Extensions
- Reactive Microservices
Kafka training, Kafka consulting, Cassandra training, Cassandra consulting, Spark training, Spark consulting