Search in sources :

Example 1 with PubSubException

use of com.yahoo.bullet.pubsub.PubSubException in project bullet-storm by yahoo.

the class QuerySpout method activate.

@Override
public void activate() {
    try {
        PubSub pubSub = PubSub.from(config);
        subscriber = pubSub.getSubscriber();
        log.info("Setup PubSub: {} with Subscriber: {}", pubSub, subscriber);
    } catch (PubSubException e) {
        throw new RuntimeException("Cannot create PubSub instance or a Subscriber for it.", e);
    }
}
Also used : PubSub(com.yahoo.bullet.pubsub.PubSub) PubSubException(com.yahoo.bullet.pubsub.PubSubException)

Example 2 with PubSubException

use of com.yahoo.bullet.pubsub.PubSubException in project bullet-storm by yahoo.

the class CustomSubscriber method receive.

@Override
public PubSubMessage receive() throws PubSubException {
    if (queue.isEmpty()) {
        throw new PubSubException("");
    }
    PubSubMessage message = queue.remove();
    received.add(message);
    return message;
}
Also used : PubSubException(com.yahoo.bullet.pubsub.PubSubException) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage)

Example 3 with PubSubException

use of com.yahoo.bullet.pubsub.PubSubException in project bullet-core by yahoo.

the class RESTSubscriber method getMessages.

@Override
public List<PubSubMessage> getMessages() throws PubSubException {
    List<PubSubMessage> messages = new ArrayList<>();
    long currentTime = System.currentTimeMillis();
    if (currentTime - lastRequest <= minWait) {
        return messages;
    }
    lastRequest = currentTime;
    for (String url : urls) {
        try {
            log.debug("Getting messages from url: ", url);
            Response response = client.prepareGet(url).execute().get();
            int statusCode = response.getStatusCode();
            if (statusCode == RESTPubSub.OK_200) {
                messages.add(PubSubMessage.fromJSON(response.getResponseBody()));
            } else if (statusCode != RESTPubSub.NO_CONTENT_204) {
                // NO_CONTENT_204 indicates there are no new messages - anything else indicates a problem
                log.error("Http call failed with status code {} and response {}.", statusCode, response);
            }
        } catch (Exception e) {
            log.error("Http call failed with error: ", e);
        }
    }
    return messages;
}
Also used : Response(org.asynchttpclient.Response) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) ArrayList(java.util.ArrayList) PubSubException(com.yahoo.bullet.pubsub.PubSubException) IOException(java.io.IOException)

Example 4 with PubSubException

use of com.yahoo.bullet.pubsub.PubSubException in project bullet-storm by yahoo.

the class DRPCResultPublisher method send.

@Override
public void send(PubSubMessage message) throws PubSubException {
    Metadata metadata = message.getMetadata();
    // Remove the content
    String content = metadata.getContent().toString();
    log.debug("Removing metadata {} for result {}@{}: {}", content, message.getId(), message.getSequence(), message.getContent());
    metadata.setContent(null);
    String serializedMessage = message.asJSON();
    Tuple tuple = new DRPCTuple(new Values(serializedMessage, content));
    // This sends the message through DRPC and not to the collector but it acks or fails accordingly.
    bolt.execute(tuple);
    if (!collector.isAcked()) {
        throw new PubSubException("Message not acked. Unable to send message through DRPC:\n " + serializedMessage);
    }
    // Otherwise, we're good to proceed
    collector.reset();
}
Also used : Metadata(com.yahoo.bullet.pubsub.Metadata) Values(org.apache.storm.tuple.Values) PubSubException(com.yahoo.bullet.pubsub.PubSubException) DRPCTuple(com.yahoo.bullet.storm.drpc.utils.DRPCTuple) DRPCTuple(com.yahoo.bullet.storm.drpc.utils.DRPCTuple) Tuple(org.apache.storm.tuple.Tuple)

Aggregations

PubSubException (com.yahoo.bullet.pubsub.PubSubException)4 PubSubMessage (com.yahoo.bullet.pubsub.PubSubMessage)2 Metadata (com.yahoo.bullet.pubsub.Metadata)1 PubSub (com.yahoo.bullet.pubsub.PubSub)1 DRPCTuple (com.yahoo.bullet.storm.drpc.utils.DRPCTuple)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Tuple (org.apache.storm.tuple.Tuple)1 Values (org.apache.storm.tuple.Values)1 Response (org.asynchttpclient.Response)1