blob: 11c1fbf621b652e4791a1ef8a78fbe709c248dff [file] [log] [blame]
////
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
= Apache Log4j Samples: connect to a Flume agent via Avro
This sample uses the classes in the sample link:../log4j-samples-flume-common[log4j-samples-flume-common] project. It will randomly pick from the events defined there and send them to Flume. At the same time it will intermix some random non-audit events.
To run this sample:
. Run `mvn install` on the `log4j-samples-flume-common` project.
. Download and install https://flume.apache.org/download.html[Apache Flume].
. Copy the link:src/main/resources/flume/conf/flume-conf.properties[flume-conf.properties] to the `conf` directory of where Flume was installed.
. In a terminal window start flume using
+
----
bin/flume-ng agent -n agent -c conf -f conf/flume-conf.properties
----
. Verify Flume started and configured an Avro source, a memory channel and a logger sink by reviewing the startup log.
. In a separate terminal window run `mvn jetty:run` in this project.
. Verify the Flume appender connected to the Flume agent by finding
+
----
Starting FlumeAvroManager FlumeAvro[localhost:8800]
----
in the Jetty log and that there are no exceptions and also by seeing something like
+
----
/127.0.0.1:53351 => /127.0.0.1:8800] OPEN
----
in the Flume log.
. In a separate terminal window in the project directory run
+
----
tail -f target/logs/app.log
----
to see the application generate non-audit logs.
. In the browser go to url http://localhost:8080/flumeAgent/start.do. A "Started" message should appear on the screen.
. After verifying logs are being written click on the Stop button in the browser page.
Note that the Flume agent must be started for the FlumeAppender to successfully start. If the Flume agent is stopped
an exception will be thrown for each event that occurs while the agent is down. When the agent restarts the
appender will automatically reconnect.
The output from the Flume agent will include the generated Flume events. Since the events are sent individually
Avro will print the full event and Flume will print a hex dump of the first few bytes of the event.