Search in sources :

Example 31 with Message

use of com.yahoo.messagebus.Message in project vespa by vespa-engine.

the class DocumentRetriever method retrieveDocuments.

public void retrieveDocuments() throws DocumentRetrieverException {
    boolean first = true;
    String route = params.cluster.isEmpty() ? params.route : resolveClusterRoute(params.cluster);
    LoadType loadType = params.loadTypeName.isEmpty() ? null : resolveLoadType(params.loadTypeName);
    MessageBusParams messageBusParams = createMessageBusParams(params.configId, params.timeout, route);
    documentAccess = documentAccessFactory.createDocumentAccess(messageBusParams);
    session = documentAccess.createSyncSession(new SyncParameters.Builder().build());
    int trace = params.traceLevel;
    if (trace > 0) {
        session.setTraceLevel(trace);
    }
    Iterator<String> iter = params.documentIds;
    if (params.jsonOutput && !params.printIdsOnly) {
        System.out.println('[');
    }
    while (iter.hasNext()) {
        if (params.jsonOutput && !params.printIdsOnly) {
            if (!first) {
                System.out.println(',');
            } else {
                first = false;
            }
        }
        String docid = iter.next();
        Message msg = createDocumentRequest(docid, loadType);
        Reply reply = session.syncSend(msg);
        printReply(reply);
    }
    if (params.jsonOutput && !params.printIdsOnly) {
        System.out.println(']');
    }
}
Also used : SyncParameters(com.yahoo.documentapi.SyncParameters) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) Reply(com.yahoo.messagebus.Reply) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) MessageBusParams(com.yahoo.documentapi.messagebus.MessageBusParams) LoadType(com.yahoo.documentapi.messagebus.loadtypes.LoadType)

Example 32 with Message

use of com.yahoo.messagebus.Message in project vespa by vespa-engine.

the class DocumentProcessingHandlerAllMessageTypesTestCase method put.

private void put() throws InterruptedException {
    Document document = new Document(getType(), "doc:baz:foo");
    document.setFieldValue("blahblah", new StringFieldValue("This is a test."));
    PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(document));
    assertTrue(sendMessage(FOOBAR, message));
    Message result = remoteServer.awaitMessage(60, TimeUnit.SECONDS);
    assertNotNull(result);
    remoteServer.ackMessage(result);
    Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS);
    assertNotNull(reply);
    assertThat(result, instanceOf(PutDocumentMessage.class));
    PutDocumentMessage outputMsg = (PutDocumentMessage) result;
    assertThat(((StringFieldValue) outputMsg.getDocumentPut().getDocument().getFieldValue("blahblah")).getString(), is("THIS IS A TEST."));
    assertFalse(reply.hasErrors());
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) BatchDocumentUpdateMessage(com.yahoo.documentapi.messagebus.protocol.BatchDocumentUpdateMessage) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Reply(com.yahoo.messagebus.Reply)

Example 33 with Message

use of com.yahoo.messagebus.Message in project vespa by vespa-engine.

the class DocumentProcessingHandlerAllMessageTypesTestCase method remove.

private void remove() throws InterruptedException {
    RemoveDocumentMessage message = new RemoveDocumentMessage(new DocumentId("doc:12345:6789"));
    assertTrue(sendMessage(FOOBAR, message));
    Message result = remoteServer.awaitMessage(60, TimeUnit.SECONDS);
    assertNotNull(result);
    remoteServer.ackMessage(result);
    Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS);
    assertNotNull(reply);
    assertThat(result, instanceOf(RemoveDocumentMessage.class));
    RemoveDocumentMessage outputMsg = (RemoveDocumentMessage) result;
    assertThat(outputMsg.getDocumentId().toString(), is("doc:12345:6789"));
    assertFalse(reply.hasErrors());
}
Also used : RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) BatchDocumentUpdateMessage(com.yahoo.documentapi.messagebus.protocol.BatchDocumentUpdateMessage) Reply(com.yahoo.messagebus.Reply)

Example 34 with Message

use of com.yahoo.messagebus.Message in project vespa by vespa-engine.

the class DocumentProcessingHandlerAllMessageTypesTestCase method update.

private void update() throws InterruptedException {
    DocumentUpdate documentUpdate = new DocumentUpdate(getType(), "doc:baz:foo");
    UpdateDocumentMessage message = new UpdateDocumentMessage(documentUpdate);
    assertTrue(sendMessage(FOOBAR, message));
    Message result = remoteServer.awaitMessage(60, TimeUnit.SECONDS);
    assertNotNull(result);
    remoteServer.ackMessage(result);
    Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS);
    assertNotNull(reply);
    assertThat(result, instanceOf(UpdateDocumentMessage.class));
    UpdateDocumentMessage outputMsg = (UpdateDocumentMessage) result;
    assertThat(outputMsg.getDocumentUpdate().getId().toString(), is("doc:baz:foo"));
    assertFalse(reply.hasErrors());
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) BatchDocumentUpdateMessage(com.yahoo.documentapi.messagebus.protocol.BatchDocumentUpdateMessage) Reply(com.yahoo.messagebus.Reply) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)

Example 35 with Message

use of com.yahoo.messagebus.Message in project vespa by vespa-engine.

the class DocumentProcessingHandlerBasicTestCase method testPut.

@Test
public void testPut() throws InterruptedException {
    Document document = new Document(getType(), "doc:yalla:balla");
    document.setFieldValue("blahblah", new StringFieldValue("This is a test."));
    PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(document));
    assertTrue(sendMessage("foobar", message));
    Message msg = remoteServer.awaitMessage(60, TimeUnit.SECONDS);
    assertNotNull(msg);
    remoteServer.ackMessage(msg);
    Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS);
    assertNotNull(reply);
    assertThat((msg instanceof PutDocumentMessage), is(true));
    PutDocumentMessage put = (PutDocumentMessage) msg;
    Document outDoc = put.getDocumentPut().getDocument();
    assertThat(document, equalTo(outDoc));
    assertFalse(reply.hasErrors());
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) Message(com.yahoo.messagebus.Message) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentPut(com.yahoo.document.DocumentPut) Reply(com.yahoo.messagebus.Reply) Document(com.yahoo.document.Document) Test(org.junit.Test)

Aggregations

Message (com.yahoo.messagebus.Message)39 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)17 RemoveDocumentMessage (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage)15 UpdateDocumentMessage (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)15 Reply (com.yahoo.messagebus.Reply)14 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)13 Test (org.junit.Test)13 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)9 Chain (com.yahoo.component.chain.Chain)7 FeedContext (com.yahoo.feedapi.FeedContext)7 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)7 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)7 Searcher (com.yahoo.search.Searcher)7 Execution (com.yahoo.search.searchchain.Execution)7 ClusterList (com.yahoo.vespaclient.ClusterList)7 Result (com.yahoo.search.Result)6 Utf8String (com.yahoo.text.Utf8String)6 BatchDocumentUpdateMessage (com.yahoo.documentapi.messagebus.protocol.BatchDocumentUpdateMessage)5 Tuple2 (com.yahoo.collections.Tuple2)4 EmptyReply (com.yahoo.messagebus.EmptyReply)4