Search in sources :

Example 26 with Message

use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.

the class TestElasticSearchDAOV5 method addMessage.

@Test
public void addMessage() {
    String messageId = "some-message-id";
    Message message = new Message();
    message.setId(messageId);
    message.setPayload("some-payload");
    message.setReceipt("some-receipt");
    indexDAO.addMessage("some-queue", message);
    await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
        SearchResponse searchResponse = search(LOG_INDEX_PREFIX + "*", "messageId='" + messageId + "'", 0, 10000, "*", MSG_DOC_TYPE);
        assertEquals("search results should be length 1", searchResponse.getHits().getTotalHits(), 1);
        SearchHit searchHit = searchResponse.getHits().getAt(0);
        GetResponse response = elasticSearchClient.prepareGet(searchHit.getIndex(), MSG_DOC_TYPE, searchHit.getId()).get();
        assertEquals("indexed message id should match", messageId, response.getSource().get("messageId"));
        assertEquals("indexed payload should match", "some-payload", response.getSource().get("payload"));
    });
    List<Message> messages = indexDAO.getMessages("some-queue");
    assertEquals(1, messages.size());
    assertEquals(message.getId(), messages.get(0).getId());
    assertEquals(message.getPayload(), messages.get(0).getPayload());
}
Also used : Message(com.netflix.conductor.core.events.queue.Message) SearchHit(org.elasticsearch.search.SearchHit) GetResponse(org.elasticsearch.action.get.GetResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) Test(org.junit.Test)

Example 27 with Message

use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.

the class ElasticSearchRestDAOV5 method mapGetMessagesResponse.

private List<Message> mapGetMessagesResponse(SearchResponse response) throws IOException {
    SearchHit[] hits = response.getHits().getHits();
    TypeFactory factory = TypeFactory.defaultInstance();
    MapType type = factory.constructMapType(HashMap.class, String.class, String.class);
    List<Message> messages = new ArrayList<>(hits.length);
    for (SearchHit hit : hits) {
        String source = hit.getSourceAsString();
        Map<String, String> mapSource = objectMapper.readValue(source, type);
        Message msg = new Message(mapSource.get("messageId"), mapSource.get("payload"), null);
        messages.add(msg);
    }
    return messages;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) Message(com.netflix.conductor.core.events.queue.Message) ArrayList(java.util.ArrayList) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) MapType(com.fasterxml.jackson.databind.type.MapType)

Example 28 with Message

use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.

the class ElasticSearchDAOV5 method mapGetMessagesResponse.

private List<Message> mapGetMessagesResponse(SearchResponse response) throws IOException {
    SearchHit[] hits = response.getHits().getHits();
    TypeFactory factory = TypeFactory.defaultInstance();
    MapType type = factory.constructMapType(HashMap.class, String.class, String.class);
    List<Message> messages = new ArrayList<>(hits.length);
    for (SearchHit hit : hits) {
        String source = hit.getSourceAsString();
        Map<String, String> mapSource = objectMapper.readValue(source, type);
        Message msg = new Message(mapSource.get("messageId"), mapSource.get("payload"), null);
        messages.add(msg);
    }
    return messages;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) Message(com.netflix.conductor.core.events.queue.Message) ArrayList(java.util.ArrayList) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) MapType(com.fasterxml.jackson.databind.type.MapType)

Example 29 with Message

use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.

the class TestElasticSearchDAOV6 method shouldAddMessage.

@Test
public void shouldAddMessage() {
    String queue = "queue";
    Message message1 = new Message(uuid(), "payload1", null);
    Message message2 = new Message(uuid(), "payload2", null);
    indexDAO.addMessage(queue, message1);
    indexDAO.addMessage(queue, message2);
    List<Message> indexedMessages = tryFindResults(() -> indexDAO.getMessages(queue), 2);
    assertEquals(2, indexedMessages.size());
    assertTrue("Not all messages was indexed", indexedMessages.containsAll(Arrays.asList(message1, message2)));
}
Also used : Message(com.netflix.conductor.core.events.queue.Message) Test(org.junit.Test)

Example 30 with Message

use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.

the class ElasticSearchDAOV6 method mapGetMessagesResponse.

private List<Message> mapGetMessagesResponse(SearchResponse response) throws IOException {
    SearchHit[] hits = response.getHits().getHits();
    TypeFactory factory = TypeFactory.defaultInstance();
    MapType type = factory.constructMapType(HashMap.class, String.class, String.class);
    List<Message> messages = new ArrayList<>(hits.length);
    for (SearchHit hit : hits) {
        String source = hit.getSourceAsString();
        Map<String, String> mapSource = objectMapper.readValue(source, type);
        Message msg = new Message(mapSource.get("messageId"), mapSource.get("payload"), null);
        messages.add(msg);
    }
    return messages;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) Message(com.netflix.conductor.core.events.queue.Message) ArrayList(java.util.ArrayList) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) MapType(com.fasterxml.jackson.databind.type.MapType)

Aggregations

Message (com.netflix.conductor.core.events.queue.Message)42 ArrayList (java.util.ArrayList)18 Test (org.junit.Test)16 LinkedList (java.util.LinkedList)12 List (java.util.List)11 ObservableQueue (com.netflix.conductor.core.events.queue.ObservableQueue)10 HashMap (java.util.HashMap)10 Collections (java.util.Collections)9 Map (java.util.Map)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 Connection (java.sql.Connection)7 Executors (java.util.concurrent.Executors)7 Task (com.netflix.conductor.common.metadata.tasks.Task)6 TimeUnit (java.util.concurrent.TimeUnit)6 Workflow (com.netflix.conductor.common.run.Workflow)5 QueueDAO (com.netflix.conductor.dao.QueueDAO)5 Collectors (java.util.stream.Collectors)5 SearchHit (org.elasticsearch.search.SearchHit)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5