use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.
the class RedisMessageReceiver method receiveMessage.
@Override
public void receiveMessage(String message) {
try {
EventMessage eventMessage = mapper.readValue(message, EventMessageImpl.class);
asyncService.executeAsync(eventMessage);
} catch (IOException e) {
logger.error("Failed prase message ", e);
}
}
use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.
the class CustomerAdapterJobDispatcher method sendMessage.
private void sendMessage(long execount, FacilitySoftwareConfig integration, FacilityAdapter adapter) {
String topic = adapter.getTopic();
String queue = adapter.getQueueName();
List<AdapterJobCommand> commands = adapter.getCommands();
for (AdapterJobCommand command : commands) {
int executeCycle = command.getTriggerCycle() / EVERY_CYCLE;
if (execount % executeCycle == 0) {
try {
template.opsForList().leftPushAll(queue, EventMessageUtil.generateFacilityMessageListByType(null, command.getCommand(), new FacilitySoftwareConfig[] { integration }));
EventMessage message = EventMessageUtil.createEventMessage(null, null, NODIFY_MESSAGE);
publisher.publish(topic, EventMessageUtil.convertEventMessageAsString(message));
logger.info("Send " + command.getCommand() + " of " + integration.getName() + " success");
} catch (IOException e) {
logger.error("Failed to send out message", e);
}
}
}
}
use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.
the class AdapterJobService method executeAsync.
@Override
public void executeAsync(EventMessage message) {
// TODO Auto-generated method stub
logger.info("message received");
String messageString = null;
while ((messageString = template.opsForList().rightPop(queueName)) != null) {
EventMessage payloadMessage = null;
try {
payloadMessage = mapper.readValue(messageString, EventMessageImpl.class);
} catch (IOException e) {
logger.error("Cannot process message", e);
}
if (payloadMessage == null) {
continue;
}
FacilitySoftwareConfig integration = null;
try {
integration = mapper.readValue(payloadMessage.getContent(), FacilitySoftwareConfig.class);
} catch (IOException e) {
logger.error("Cannot process message", e);
}
if (null == integration) {
continue;
}
if (!integration.checkIsActive()) {
continue;
}
for (EventUser payloadCommand : payloadMessage.getTarget().getUsers()) {
excuteJob(payloadCommand.getId(), integration);
}
}
}
use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.
the class RedisMessageReceiver method receiveMessage.
@Override
public void receiveMessage(String message) {
try {
EventMessage eventMessage = mapper.readValue(message, EventMessageImpl.class);
asyncService.executeAsync(eventMessage);
} catch (IOException e) {
logger.info(String.format("Failed prase message %s", message));
}
}
use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.
the class MessageProcessingTest method testMessage.
@Test
public void testMessage() {
ObjectMapper mapper = new ObjectMapper();
String template = "{\"type\":\"InfoBlox\",\"eventUser\":null,\"source\":null,\"target\":null,\"createTime\":%s,\"content\":\"nihao\"}";
long time = new Date().getTime();
EventMessage message = new EventMessageImpl(EventType.InfoBlox, null, null, null, time, "nihao");
String bb;
try {
bb = mapper.writeValueAsString(message);
Assert.assertEquals(String.format(template, time), bb);
EventMessage mess2 = mapper.readValue(bb, EventMessageImpl.class);
Assert.assertEquals("nihao", mess2.getContent());
String gg = "{\"type\":\"InfoBlox\",\"createTime\":1539073715966,\"content\":\"helloworld\"}";
EventMessage mess3 = mapper.readValue(gg, EventMessageImpl.class);
Assert.assertEquals("helloworld", mess3.getContent());
} catch (IOException e) {
Assert.fail();
}
}
Aggregations