Tabnine Logo
PubSubMessage.asJSON
Code IndexAdd Tabnine to your IDE (free)

How to use
asJSON
method
in
com.yahoo.bullet.pubsub.PubSubMessage

Best Java code snippets using com.yahoo.bullet.pubsub.PubSubMessage.asJSON (Showing top 9 results out of 315)

origin: com.yahoo.bullet/bullet-core

@Override
public String toString() {
  return asJSON();
}
origin: com.yahoo.bullet/bullet-core

  private HttpPost makeHttpPost(String url, PubSubMessage message) throws UnsupportedEncodingException {
    HttpPost httpPost = new HttpPost(url);
    httpPost.setEntity(new StringEntity(message.asJSON()));
    httpPost.setHeader(CONTENT_TYPE, APPLICATION_JSON);
    RequestConfig requestConfig =
        RequestConfig.custom().setConnectTimeout(connectTimeout).setSocketTimeout(connectTimeout).build();
    httpPost.setConfig(requestConfig);
    return httpPost;
  }
}
origin: com.yahoo.bullet/bullet-core

/**
 * Send the {@link PubSubMessage} to the given url.
 *
 * @param url The url to which to send the message.
 * @param message The message to send.
 */
protected void sendToURL(String url, PubSubMessage message) {
  log.debug("Sending message: {} to url: {}", message, url);
  try (CloseableHttpResponse response = client.execute(makeHttpPost(url, message))) {
    if (response == null || response.getStatusLine().getStatusCode() != RESTPubSub.OK_200) {
      log.error("Couldn't POST to REST pubsub server. Got response: {}", response);
    }
  } catch (Exception e) {
    log.error("Error when trying to POST. Message was: {}. Error was: ", message.asJSON(), e);
  }
}
origin: bullet-db/bullet-storm

public static String makeMessage(String id, String content, int sequence) {
  return new PubSubMessage(id, content, sequence).asJSON();
}
public static Object makeMessageID(String id, int index) {
origin: com.yahoo.bullet/bullet-storm

@Override
public void send(PubSubMessage message) throws PubSubException {
  String url = urls.get();
  String id = message.getId();
  String json = message.asJSON();
  log.info("Posting to {} for id {}", url, id);
  log.debug("Posting to {} with body {}", url, json);
  client.preparePost(url).setBody(json).execute().toCompletableFuture()
     .exceptionally(this::handleException)
     .thenAcceptAsync(createResponseConsumer(id));
}
origin: bullet-db/bullet-storm

@Override
public void send(PubSubMessage message) throws PubSubException {
  String url = urls.get();
  String id = message.getId();
  String json = message.asJSON();
  log.info("Posting to {} for id {}", url, id);
  log.debug("Posting to {} with body {}", url, json);
  client.preparePost(url).setBody(json).execute().toCompletableFuture()
     .exceptionally(this::handleException)
     .thenAcceptAsync(createResponseConsumer(id));
}
origin: bullet-db/bullet-storm

@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();
}
origin: com.yahoo.bullet/bullet-storm

@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();
}
origin: bullet-db/bullet-storm

@Test(timeOut = 5000L)
public void testReadingOkResponse() throws Exception {
  PubSubMessage expected = new PubSubMessage("foo", "response");
  CompletableFuture<Response> response = getOkFuture(getOkResponse(expected.asJSON()));
  AsyncHttpClient mockClient = mockClientWith(response);
  pubscriber.setClient(mockClient);
  pubscriber.send(new PubSubMessage("foo", "bar"));
  // This is async (but practically still very fast since we mocked the response), so need a timeout.
  PubSubMessage actual = fetchAsync().get();
  Assert.assertNotNull(actual);
  Assert.assertEquals(actual.getId(), expected.getId());
  Assert.assertEquals(actual.getContent(), expected.getContent());
}
com.yahoo.bullet.pubsubPubSubMessageasJSON

Popular methods of PubSubMessage

  • <init>
    Constructor for a message having content, Metadata and a sequence number.
  • getId
  • getMetadata
  • getSequence
  • fromJSON
    Converts a json representation back to an instance.
  • getContent
  • hasMetadata
    Check if message has Metadata.
  • hasSignal
    Check if message has a given Signal.
  • setMetadata

Popular in Java

  • Parsing JSON documents to java classes using gson
  • putExtra (Intent)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getSharedPreferences (Context)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • Kernel (java.awt.image)
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now