use of org.springframework.kafka.annotation.KafkaListener in project open-kilda by telstra.
the class KafkaMessageConsumer method receive.
/**
* Receives messages from WorkFlowManager queue.
*
* @param record the message object instance
*/
@KafkaListener(topics = "kilda-test")
public void receive(final String record) {
logger.debug("message received: {}", record);
try {
Message message = MAPPER.readValue(record, Message.class);
if (message.getDestination() == null || Destination.TOPOLOGY_ENGINE.equals(message.getDestination())) {
if (message instanceof CommandMessage) {
CommandData data = ((CommandMessage) message).getData();
if (data instanceof FlowCreateRequest) {
FlowPayload payload = ((FlowCreateRequest) data).getPayload();
logger.debug("FlowCreateRequest: {}", payload);
Set<CommandMessage> commands = flowService.createFlow(payload, message.getCorrelationId());
for (CommandMessage response : commands) {
kafkaMessageProducer.send(topic, response);
}
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowDeleteRequest) {
FlowIdStatusPayload payload = ((FlowDeleteRequest) data).getPayload();
logger.debug("FlowDeleteRequest: {}", payload);
Set<CommandMessage> commands = flowService.deleteFlow(payload, message.getCorrelationId());
for (CommandMessage response : commands) {
kafkaMessageProducer.send(topic, response);
}
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowUpdateRequest) {
FlowPayload payload = ((FlowUpdateRequest) data).getPayload();
logger.debug("FlowUpdateRequest: {}", payload);
Set<CommandMessage> commands = flowService.updateFlow(payload, message.getCorrelationId());
for (CommandMessage response : commands) {
kafkaMessageProducer.send(topic, response);
}
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowGetRequest) {
FlowIdStatusPayload payload = ((FlowGetRequest) data).getPayload();
logger.debug("FlowGetRequest: {}", payload);
InfoMessage response = flowService.getFlow(payload, message.getCorrelationId());
kafkaMessageProducer.send(topic, response);
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowsGetRequest) {
FlowIdStatusPayload payload = ((FlowsGetRequest) data).getPayload();
logger.debug("FlowsGetRequest: {}", payload);
InfoMessage response = flowService.getFlows(payload, message.getCorrelationId());
kafkaMessageProducer.send(topic, response);
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowPathRequest) {
FlowIdStatusPayload payload = ((FlowPathRequest) data).getPayload();
logger.debug("FlowPathRequest: {}", payload);
InfoMessage response = flowService.pathFlow(payload, message.getCorrelationId());
kafkaMessageProducer.send(topic, response);
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else {
logger.error("Unexpected command message data type: {}", data);
}
} else if (message instanceof InfoMessage) {
InfoData data = ((InfoMessage) message).getData();
if (data instanceof SwitchInfoData) {
SwitchInfoData payload = (SwitchInfoData) data;
switch(payload.getState()) {
case ADDED:
switchService.add(payload);
break;
case ACTIVATED:
switchService.activate(payload);
break;
case DEACTIVATED:
switchService.deactivate(payload);
break;
case REMOVED:
switchService.remove(payload);
break;
case CHANGED:
default:
break;
}
} else if (data instanceof IslInfoData) {
IslInfoData payload = (IslInfoData) data;
islService.discoverLink(payload);
} else {
logger.debug("Unexpected info message data type: {}", data);
}
}
} else {
logger.debug("Skip message: {}", message);
}
} catch (IOException exception) {
logger.error("Could not deserialize message: {}", record, exception);
}
}
use of org.springframework.kafka.annotation.KafkaListener in project open-kilda by telstra.
the class KafkaMessageConsumer method receive.
/**
* Receives messages from WorkFlowManager queue.
*
* @param record the message object instance
*/
@KafkaListener(id = "northbound-listener", topics = Topic.NORTHBOUND)
public void receive(final String record) {
try {
logger.trace("message received");
Message message = MAPPER.readValue(record, Message.class);
if (Destination.NORTHBOUND.equals(message.getDestination())) {
logger.debug("message received: {}", record);
messages.put(message.getCorrelationId(), message);
} else {
logger.trace("Skip message: {}", message);
}
} catch (IOException exception) {
logger.error("Could not deserialize message: {}", record, exception);
}
}
use of org.springframework.kafka.annotation.KafkaListener in project summer by foxsugar.
the class UserServiceMsgConsumer method listen.
@KafkaListener(id = "userService", topicPattern = "userService")
public void listen(ConsumerRecord<String, String> record) {
ThreadPool.getInstance().executor.execute(() -> {
String key = record.key();
String value = record.value();
KafkaMsgKey msgKey = JsonUtil.readValue(key, KafkaMsgKey.class);
JsonNode msgValue = JsonUtil.readTree(value);
UserServiceMsgDispatch userServiceMsgDispatch = SpringUtil.getBean(UserServiceMsgDispatch.class);
userServiceMsgDispatch.dispatchMsg(msgKey, msgValue);
});
}
use of org.springframework.kafka.annotation.KafkaListener in project summer by foxsugar.
the class UserServiceMsgConsumer method listen3.
@KafkaListener(id = "clubService", topicPattern = "clubService")
public void listen3(ConsumerRecord<String, String> record) {
String key = record.key();
String value = record.value();
KafkaMsgKey msgKey = JsonUtil.readValue(key, KafkaMsgKey.class);
JsonNode msgValue = JsonUtil.readTree(value);
ClubServiceMsgDispatch clubServiceMsgDispatch = SpringUtil.getBean(ClubServiceMsgDispatch.class);
clubServiceMsgDispatch.dispatchMsg(msgKey, msgValue);
}
use of org.springframework.kafka.annotation.KafkaListener in project micro-service by Zephery.
the class MsgConsumer method processMessage.
@KafkaListener(topics = { "nginx-access-log" })
public void processMessage(String content) {
JsonObject object = parser.parse(content).getAsJsonObject();
String upstreamhost = object.get("upstreamhost").getAsString();
map.put(upstreamhost, map.get("upstreamhost") == null ? 1 : map.get("upstreamhost") + 1);
for (Map.Entry<String, Integer> entry : map.entrySet()) {
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
}
Aggregations