Search in sources :

Example 26 with EventMessage

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);
    }
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) IOException(java.io.IOException)

Example 27 with EventMessage

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);
            }
        }
    }
}
Also used : AdapterJobCommand(com.vmware.flowgate.common.model.AdapterJobCommand) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) IOException(java.io.IOException)

Example 28 with EventMessage

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);
        }
    }
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) EventMessageImpl(com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl) EventUser(com.vmware.flowgate.common.model.redis.message.EventUser) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) IOException(java.io.IOException)

Example 29 with EventMessage

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));
    }
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) IOException(java.io.IOException)

Example 30 with EventMessage

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();
    }
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) EventMessageImpl(com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Date(java.util.Date) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)33 IOException (java.io.IOException)24 EventUser (com.vmware.flowgate.common.model.redis.message.EventUser)8 EventMessageImpl (com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl)8 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)7 Test (org.junit.Test)6 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 Asset (com.vmware.flowgate.common.model.Asset)4 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)4 ArrayList (java.util.ArrayList)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Async (org.springframework.scheduling.annotation.Async)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AssetIPMapping (com.vmware.flowgate.common.model.AssetIPMapping)2 Date (java.util.Date)2 AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)1 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)1