我有以下的在我的春天啓動的應用程序的反應器結構:使用干擾器與彈簧引導
@Configuration
public class AsyncConfig {
@Bean
public EventBus eventBus(){
return EventBus.create(getDispatcher("rb-relay"));
}
public MultiThreadDispatcher getDispatcher(String name){
return new WorkQueueDispatcher(name, 4, 1024, null);
}
}
基本上我在做什麼是這樣的:每當一個請求到達終點我,我將其轉發至其他終端在我的應用程序中註冊。爲此,我派遣每個傳入請求總線:
@Service
public class URLRelayPublisher {
@Autowired
EventBus bus;
@Autowired
DestinationURLRepository repository;
public void relay(HttpServletRequest request){
repository.findAll()
.forEach(destinationURL -> bus.notify("relay", Event.wrap(new RelayEvent(destinationURL, request))));
}
}
和我的消費
@Component
@Log
public class URLRelayReceiver implements Consumer<Event<RelayEvent>> {
@Autowired
RestTemplate template;
@Override
public void accept(Event<RelayEvent> relayEvent) {
try{
HttpServletRequest request = relayEvent.getData().getRequest();
DestinationURL destinationURL = relayEvent.getData().getDestinationURL();
log.info("Relaying for "+destinationURL.getUrl());
Map<String, String> headers = buildHeader(request);
template.postForLocation(destinationURL.getUrl(), headers, request.getParameterMap());
}catch (RestClientException e){
log.info("Could not relay event: "+e.getMessage());
}
}
干擾器號稱處理周圍6-8米TPS,雖然當我siege
應用程序(siege -d 2 -c 50 -t30S -H 'Content-Type: application/json' -H 'Auth-Token: qyz3kHZFuXRw8nm14uYLjLNoQ' 'http://127.0.0.1:8080/callback POST {"content": "message"}'
)我得到96 TPS左右的東西。我的問題是:1)配置是否足以使用Disruptor? 2)如何確保我在這裏使用Disruptor?