Java Code Examples for org.apache.flume.event.SimpleEvent#setHeaders()
The following examples show how to use
org.apache.flume.event.SimpleEvent#setHeaders() .
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 |
@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: TestElasticSearchIndexRequestBuilderFactory.java From mt-flume with Apache License 2.0 | 5 votes |
@Test public void shouldUseExistingTimestampHeaderInTimestampedEvent() { SimpleEvent base = new SimpleEvent(); Map<String, String> headersWithTimestamp = Maps.newHashMap(); headersWithTimestamp.put("timestamp", "-321"); base.setHeaders(headersWithTimestamp ); TimestampedEvent timestampedEvent = new TimestampedEvent(base); assertEquals(-321L, timestampedEvent.getTimestamp()); assertEquals("-321", timestampedEvent.getHeaders().get("timestamp")); }
Example 3
Source File: TestElasticSearchIndexRequestBuilderFactory.java From mt-flume with Apache License 2.0 | 5 votes |
@Test public void shouldUseExistingAtTimestampHeaderInTimestampedEvent() { SimpleEvent base = new SimpleEvent(); Map<String, String> headersWithTimestamp = Maps.newHashMap(); headersWithTimestamp.put("@timestamp", "-999"); base.setHeaders(headersWithTimestamp ); TimestampedEvent timestampedEvent = new TimestampedEvent(base); assertEquals(-999L, timestampedEvent.getTimestamp()); assertEquals("-999", timestampedEvent.getHeaders().get("@timestamp")); assertNull(timestampedEvent.getHeaders().get("timestamp")); }
Example 4
Source File: TestElasticSearchIndexRequestBuilderFactory.java From mt-flume with Apache License 2.0 | 5 votes |
@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 |
@Test public void shouldUseExistingTimestampHeaderInTimestampedEvent() { SimpleEvent base = new SimpleEvent(); Map<String, String> headersWithTimestamp = Maps.newHashMap(); headersWithTimestamp.put("timestamp", "-321"); base.setHeaders(headersWithTimestamp ); TimestampedEvent timestampedEvent = new TimestampedEvent(base); assertEquals(-321L, timestampedEvent.getTimestamp()); assertEquals("-321", timestampedEvent.getHeaders().get("timestamp")); }
Example 6
Source File: TimestampedEventTest.java From ingestion with Apache License 2.0 | 5 votes |
@Test public void shouldUseExistingAtTimestampHeaderInTimestampedEvent() { SimpleEvent base = new SimpleEvent(); Map<String, String> headersWithTimestamp = Maps.newHashMap(); headersWithTimestamp.put("@timestamp", "-999"); base.setHeaders(headersWithTimestamp ); TimestampedEvent timestampedEvent = new TimestampedEvent(base); assertEquals(-999L, timestampedEvent.getTimestamp()); assertEquals("-999", timestampedEvent.getHeaders().get("@timestamp")); assertNull(timestampedEvent.getHeaders().get("timestamp")); }
Example 7
Source File: TimestampedEventTest.java From ingestion with Apache License 2.0 | 5 votes |
@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 8
Source File: TestElasticSearchIndexRequestBuilderFactory.java From ingestion with Apache License 2.0 | 5 votes |
@Test public void shouldUseExistingTimestampHeaderInTimestampedEvent() { SimpleEvent base = new SimpleEvent(); Map<String, String> headersWithTimestamp = Maps.newHashMap(); headersWithTimestamp.put("timestamp", "-321"); base.setHeaders(headersWithTimestamp ); TimestampedEvent timestampedEvent = new TimestampedEvent(base); assertEquals(-321L, timestampedEvent.getTimestamp()); assertEquals("-321", timestampedEvent.getHeaders().get("timestamp")); }
Example 9
Source File: TestElasticSearchIndexRequestBuilderFactory.java From ingestion with Apache License 2.0 | 5 votes |
@Test public void shouldUseExistingAtTimestampHeaderInTimestampedEvent() { SimpleEvent base = new SimpleEvent(); Map<String, String> headersWithTimestamp = Maps.newHashMap(); headersWithTimestamp.put("@timestamp", "-999"); base.setHeaders(headersWithTimestamp ); TimestampedEvent timestampedEvent = new TimestampedEvent(base); assertEquals(-999L, timestampedEvent.getTimestamp()); assertEquals("-999", timestampedEvent.getHeaders().get("@timestamp")); assertNull(timestampedEvent.getHeaders().get("timestamp")); }
Example 10
Source File: TestElasticSearchIndexRequestBuilderFactory.java From ingestion with Apache License 2.0 | 5 votes |
@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 11
Source File: FlumePersistentManager.java From logging-log4j2 with Apache License 2.0 | 5 votes |
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; } }