Java Code Examples for org.apache.flume.event.SimpleEvent#setBody()

The following examples show how to use org.apache.flume.event.SimpleEvent#setBody() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlumeLogAppender.java    From chassis with Apache License 2.0 6 votes vote down vote up
@Override
protected void append(ILoggingEvent logEvent) {
	SimpleEvent flumeEvent = new SimpleEvent();
	
	Map<String, String> headers = new HashMap<>();
	headers.put("timestamp", "" + logEvent.getTimeStamp());
	headers.put("level", logEvent.getLevel().levelStr);
	headers.put("threadName", logEvent.getThreadName());
	headers.put("loggerName", logEvent.getLoggerName());
	headers.put("product", product);
	headers.put("hostname", NetworkingUtils.getIpAddress());
	flumeEvent.setHeaders(headers);
	flumeEvent.setBody(logEvent.getFormattedMessage().getBytes(Charsets.UTF_8));
	
	try {
		agent.put(flumeEvent);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 2
Source File: SimpleFlumeAvroClient.java    From SparkOnALog with Apache License 2.0 5 votes vote down vote up
protected static SimpleEvent generateEvent(int i) {
	SimpleEvent event = new SimpleEvent();

	char c1 = (char) (i % 26 + 65);
	char c2 = (char) (System.currentTimeMillis() % 26 + 65);

	String body = "Event body " + c1 + " " + c2;
	event.setBody(body.getBytes());
	return event;
}
 
Example 3
Source File: RandomWordEventFlumeAvroClient.java    From SparkOnALog with Apache License 2.0 5 votes vote down vote up
protected static SimpleEvent generateEvent(int i) {
	SimpleEvent event = new SimpleEvent();
	
	char c1 = (char)(i % 26 + 65);
	char c2 = (char)(System.currentTimeMillis() % 26 + 65);
	
	String body = "Event body " + c1 + " " + c2;
	event.setBody(body.getBytes());
	return event;
}
 
Example 4
Source File: TestElasticSearchIndexRequestBuilderFactory.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPreserveBodyAndNonTimestampHeadersInTimestampedEvent() {
  SimpleEvent base = new SimpleEvent();
  base.setBody(new byte[] {1,2,3,4});
  Map<String, String> headersWithTimestamp = Maps.newHashMap();
  headersWithTimestamp.put("foo", "bar");
  base.setHeaders(headersWithTimestamp );

  TimestampedEvent timestampedEvent = new TimestampedEvent(base);
  assertEquals("bar", timestampedEvent.getHeaders().get("foo"));
  assertArrayEquals(base.getBody(), timestampedEvent.getBody());
}
 
Example 5
Source File: TimestampedEventTest.java    From ingestion with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPreserveBodyAndNonTimestampHeadersInTimestampedEvent() {
  SimpleEvent base = new SimpleEvent();
  base.setBody(new byte[] {1,2,3,4});
  Map<String, String> headersWithTimestamp = Maps.newHashMap();
  headersWithTimestamp.put("foo", "bar");
  base.setHeaders(headersWithTimestamp );

  TimestampedEvent timestampedEvent = new TimestampedEvent(base);
  assertEquals("bar", timestampedEvent.getHeaders().get("foo"));
  assertArrayEquals(base.getBody(), timestampedEvent.getBody());
}
 
Example 6
Source File: TestElasticSearchIndexRequestBuilderFactory.java    From ingestion with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPreserveBodyAndNonTimestampHeadersInTimestampedEvent() {
  SimpleEvent base = new SimpleEvent();
  base.setBody(new byte[] {1,2,3,4});
  Map<String, String> headersWithTimestamp = Maps.newHashMap();
  headersWithTimestamp.put("foo", "bar");
  base.setHeaders(headersWithTimestamp );

  TimestampedEvent timestampedEvent = new TimestampedEvent(base);
  assertEquals("bar", timestampedEvent.getHeaders().get("foo"));
  assertArrayEquals(base.getBody(), timestampedEvent.getBody());
}
 
Example 7
Source File: FlumePersistentManager.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private SimpleEvent createEvent(final DatabaseEntry data) {
    final SimpleEvent event = new SimpleEvent();
    try {
        byte[] eventData = data.getData();
        if (secretKey != null) {
            final Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, secretKey);
            eventData = cipher.doFinal(eventData);
        }
        final ByteArrayInputStream bais = new ByteArrayInputStream(eventData);
        final DataInputStream dais = new DataInputStream(bais);
        int length = dais.readInt();
        final byte[] bytes = new byte[length];
        dais.read(bytes, 0, length);
        event.setBody(bytes);
        length = dais.readInt();
        final Map<String, String> map = new HashMap<>(length);
        for (int i = 0; i < length; ++i) {
            final String headerKey = dais.readUTF();
            final String value = dais.readUTF();
            map.put(headerKey, value);
        }
        event.setHeaders(map);
        return event;
    } catch (final Exception ex) {
        LOGGER.error("Error retrieving event", ex);
        return null;
    }
}
 
Example 8
Source File: JettyWebSocketListener.java    From sequenceiq-samples with Apache License 2.0 4 votes vote down vote up
private SimpleEvent createEvent(String message) {
    SimpleEvent event = new SimpleEvent();
    event.setBody(message.getBytes());
    return event;
}
 
Example 9
Source File: S3Source.java    From sequenceiq-samples with Apache License 2.0 4 votes vote down vote up
private SimpleEvent createEvent(String message) {
    SimpleEvent event = new SimpleEvent();
    event.setBody(message.getBytes());
    return event;
}
 
Example 10
Source File: JettyWebSocketListener.java    From sequenceiq-samples with Apache License 2.0 4 votes vote down vote up
private SimpleEvent createEvent(String message) {
    SimpleEvent event = new SimpleEvent();
    event.setBody(message.getBytes());
    return event;
}