Message Queue for Apache Kafka can be connected to Filebeat as an input. This topic describes how to use Filebeat to consume messages in Message Queue for Apache Kafka in a virtual private cloud (VPC) environment.

Background information

Ensure that you have completed the following operations:
  • You have purchased and deployed a Message Queue for Apache Kafka instance. For more information, see Access from VPC.
  • You have downloaded and installed Filebeat. For more information, see Download Filebeat.
  • You have downloaded and installed Java Development Kit (JDK) 8. For more information, see Download JDK 8.

Step 1: Obtain an endpoint

Filebeat establishes a connection to Message Queue for Apache Kafka through a Message Queue for Apache Kafka endpoint.

  1. Log on to the Message Queue for Apache Kafka console.
  2. In the left-side navigation pane, click Instances.
  3. On the Instance Details page, select the instance that is to be connected to Filebeat as an input.
  4. In the Basic Information section, obtain the endpoint of the instance.
    basic info
    Note For information about the differences between endpoints, see Endpoint comparison.

Step 2: Create a topic

Perform the following operations to create a topic for storing messages.

  1. In the left-side navigation pane of the Message Queue for Apache Kafka console, click Topics.
  2. On the Topics page, click Create Topic.
  3. In the Create Topic dialog box, enter the topic information and click Create.
    create_topic

Step 3: Send messages

Perform the following operations to send messages to the topic you created.

  1. On the Topics page of the Message Queue for Apache Kafka console, find the topic you created and click Send Message in the Actions column.
  2. In the Send Message dialog box, enter the message information and click Send.
    send_msg

Step 4: Create a consumer group

Perform the following operations to create a consumer group for Filebeat.

  1. In the left-side navigation pane of the Message Queue for Apache Kafka console, click Consumer Groups.
  2. On the Consumer Groups page, click Create Consumer Group.
  3. In the Create Consumer Group dialog box, enter the consumer group information and click Create.
    create_cg

Step 5: Use Filebeat to consume messages

Start Filebeat on the server where Filebeat has been installed to consume messages from the created topic.

  1. Run the following command to switch to the installation directory of Filebeat:
    cd /root/filebeat/filebeat-7.7.0-linux-x86_64
  2. Create the input.yml configuration file.
    1. Run the vim input.yml command.
    2. Press i.
    3. Enter the following content:
      filebeat.inputs:
      - type: kafka
        hosts:
          - 192.168.XX.XX:9092
          - 192.168.XX.XX:9092
          - 192.168.XX.XX:9092
        topics: ["filebeat_test"]
        group_id: "filebeat_group"
      
      output.console:
        pretty: true
      Parameter Description Example
      type The input type of Filebeat. kafka
      hosts Message Queue for Apache Kafka supports the following VPC endpoints:
      • Default endpoint
      • SASL endpoint
      - 192.168.XX.XX:9092
      - 192.168.XX.XX:9092
      - 192.168.XX.XX:9092
      topics The name of the topic. filebeat_test
      group_id The name of the consumer group. filebeat_group

      For more information about parameter settings, see Kafka input plugin.

    4. Press Esc, enter :wq, and then press Enter.
  3. Run the following command to consume messages:
    ./filebeat -c ./tasks/vpc/input.yml
    result