Disruptor 使用。
parent
2663dbe851
commit
6be2e97075
@ -0,0 +1,18 @@
|
||||
package com.kiisoo.ic.job;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class DTOMessage {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private double price;
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.kiisoo.ic.job;
|
||||
|
||||
import com.lmax.disruptor.EventTranslator;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class DTOMessageEventTranslator implements EventTranslator<DTOMessage> {
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
private DTOMessage generateTradeTransaction(DTOMessage trade) {
|
||||
// System.out.println("DTOMessageEventTranslator" + trade.toString());
|
||||
return trade;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateTo(DTOMessage dtoMessage, long l) {
|
||||
this.generateTradeTransaction(dtoMessage);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.kiisoo.ic.job;
|
||||
|
||||
import com.lmax.disruptor.dsl.Disruptor;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class DTOMessagePublish implements Runnable {
|
||||
private Disruptor<DTOMessage> disruptor;
|
||||
private CountDownLatch latch;
|
||||
|
||||
public DTOMessagePublish(Disruptor<DTOMessage> disruptor, CountDownLatch latch) {
|
||||
this.disruptor = disruptor;
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
disruptor.publishEvent(new DTOMessageEventTranslator());
|
||||
}
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue