Koper is a MQ-based and event-driven distributed programming framework. [中文README]
-
Koper provides a simplified distributed listener and data listener model,which can help you build your async application in a simple way.
- Core architecture: Message Architeture, Event Driven Architecture(EDA)
- Core concept: producer, consumer, message, Message Queue(MQ), topic, subscribe
- Core component: MessageSender, MessageListener, DataEventListener.
- High-level concept: consumer group, message partition
- Simplified MQ-based listener model and API.
- Simplified Data Event model and API.
- MQ provider independent.
- Koper supports Kafka by default, but also supports other message queue as provider, e.g. RabbitMQ, RocketMQ.
- High performance and throughput.
- High scalability based on MQ.
- High-level feature: time spot recording, message tracking.
Member signup example. When a member signs up, a message is sent to MQ by messageSender.
messageSender.send("koper.memberSignup", "Signed up successfully! " + member.getPhoneNo());
On the other hand, a consumer subscribes the topic and handle the message, e.g. send a SMS to notify member.
@Component
@Listen(topic = "koper.memberSignup")
public class MemberSignupListener {
@Autowired
private SmsService smsService;
public void onMessage(String msg) {
smsService.sendSms(msg);
}
}
Order example.
Koper support EDA programming. The Data Event machanism can intercept method invocation of object(such as DAO) and send it to MQ as data event.
orderDao.insertOrder( order);
orderDao.updateOrder( order);
DataListener responds to the event.
@Component
@DataListener(dataObject = "koper.message.demo.dataevent.dao.impl.OrderDaoImpl")
public class OrderListener {
// data event: onInsertOrder
public void onInsertOrder(Order order) {
System.out.println("orderNo : " + order.getOrderNo());
System.out.println("create time : " + order.getCreatedTime());
// do some other operations
}
//data event: onUpdateOrder
public void onUpdateOrder(Order order) {
System.out.println("orderNo : " + order.getOrderNo());
// do some other operations such as cache refresh
}
//data event: exception on updateOrder
public void onUpdateOrder_X(Order order, DataEvent event) {
String ex = event.getException();
System.out.println("onUpdateOrder exception :" +ex);
}
}
Koper is designed to support distributed asynchornous programming based on Message Queue and Event Driven Ahchitecture. It's suitable for scenarios such as Web Application, Business Monitor, Data statistics or Big Data etc.
In a large-scale application, the system architecture and event driven architecture look like something below.
- Asynchronous Business Process
- Distributed Data Update or Cache Update
- Data Log
- Business Monitor and Alarm
Refer to Async Scenarios and examples for more demos.
Feel free to Fork
the source code and commit bug fix or enhancement. And then make a pull request to us.
Koper provides a Kafka provider implementation by default, but also provides high extensibility. You can implement other MQ provider easily, such as RabbitMQ, RocketMQ, ActiveMQ etc.
Refer to Developer Guide for details.