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);
}
}
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;
}
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;
}
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();
}
Aggregations