Skip to main content
Version: Next

1. Overview

1.1 Plugin Name#

  • Logging-RabbitMQ Plugin

1.2 Appropriate Scenario#

  • collect http request log to rabbitmq, consume rabbitmq message to another application and analysis.

1.3 Plugin functionality#

Apache ShenYu The gateway receives requests from the client, forwards them to the server, and returns the server results to the client. The gateway can record the details of each request,
The list includes: request time, request parameters, request path, response result, response status code, time consumption, upstream IP, exception information waiting.
The Logging-RabbitMQ plugin is a plugin that records access logs and sends them to the RabbitMQ cluster.

1.4 Plugin code#

  • Core Module shenyu-plugin-logging-rabbitmq.

  • Core Class org.apache.shenyu.plugin.logging.rabbitmq.LoggingRabbitmqPlugin

  • Core Claas org.apache.shenyu.plugin.logging.rabbitmq.client.RabbitmqLogCollectClient

1.5 Added Since Which shenyu version#

  • Since ShenYu 2.5.0

1.6 Technical Solutions#

  • Architecture Diagram

  • Full asynchronous collection and delivery of Logging inside the Apache ShenYu gateway

  • Logging platform by consuming the logs in the RabbitMQ cluster for repository, and then using Grafana, Kibana or other visualization platform to display

2. How to use plugin

2.1 Plugin-use procedure chart#

2.2 Import pom#

  • Add the Logging-RabbitMQ dependency to the gateway's pom.xml file.
<!--shenyu logging-rabbitmq plugin start--><dependency>    <groupId>org.apache.shenyu</groupId>    <artifactId>shenyu-spring-boot-starter-plugin-logging-rabbitmq</artifactId>    <version>${project.version}</version></dependency><!--shenyu logging-rabbitmq plugin end-->

2.3 Enable plugin#

  • In shenyu-admin --> Basic Configuration --> Plugin Management --> loggingRabbitMQ, configure the rabbitMQ parameter and set it to on.

2.4 Config plugin#

2.4.1 Open the plugin and configure rabbitmq, configure it as follows.#

  • The individual configuration items are described as follows:
config-itemtypedescriptionremarks
hosttypeIP必须
porttypePORT必须
usernameStringrabbitmq username可选
passwordStringrabbitmq password可选
virtualHostStringrabbitmq virtualHost必须,默认/
exchangeTypeStringrabbitmq exchange type必须,默认direct
exchangeNameStringrabbitmq exchange name必须
queueNameStringrabbitmq queue name必须
routingKeyStringrabbitmq routing key必须
durableBooleanmessage durable必须,默认true
exclusiveBooleanmessage exclusive必须,默认false
autoDeleteStringmessage auto delete必须,默认false
argsStringrabbitmq args,exaple:{"x-delay":"1000"},delay queue可选
sampleRateStringSampling rate, range 0~1, 0: off, 0.01: acquisition 1%, 1: acquisition 100%Optional, default 1, all collection
maxResponseBodyIngeterMaximum response size, above the threshold no response will be collectedOptional, default 512KB
maxRequestBodyIngeterMaximum request body size, above the threshold no request body will be collectedOptional, default 512KB

Except for host,port,virtualHost,exchangeType,exchangeName,queueName,routingKey,durable,exclusive,autoDelete, all others are optional.

2.4.2 Configuring Selectors and Rulers#

In addition, sometimes a large gateway cluster corresponds to multiple applications (business), different applications (business) corresponds to different topics, related to isolation,
then you can configure different topics (optional) and sampling rate (optional) by selector, the meaning of the configuration items as shown in the table above.
The operation is shown below:

2.5 Logging Info#

collect request info as follows

Field NameMeaningDescriptionRemarks
clientIpClient IP
timeLocalRequest time string, format: yyyy-MM-dd HH:mm:ss.SSS
methodrequest method (different rpc type is not the same, http class for: get, post wait, rpc class for the interface name)
requestHeaderRequest header (json format)
responseHeaderResponse header (json format)
queryParamsRequest query parameters
requestBodyRequest Body (body of binary type will not be captured)
requestUriRequest uri
responseBodyResponse body
responseContentLengthResponse body size
rpcTyperpc type
statusresponse status
upstreamIpUpstream (program providing the service) IP
upstreamResponseTimeTime taken by the upstream (program providing the service) to respond to the request (ms ms)
userAgentRequested user agent
hostThe requested host
moduleRequested modules
pathThe requested path
traceIdRequested Link Tracking IDNeed to access link tracking plugins, such as skywalking,zipkin

2.6 Examples#

2.6.1 Collect Http Log by RabbitMQ#

2.6.1.1 Plugin Configuration#

Open the plugin and configure rabbitmq, configure it as follows.

2.6.1.2 Selector Configuration#

For detailed configuration of selectors and rules, please refer to: Selector and rule management

In addition, sometimes a large gateway cluster corresponds to multiple applications (business), different applications (business) corresponds to different topics, related to isolation,
then you can configure different topics (optional) and sampling rate (optional) by selector, the meaning of the configuration items as shown in the table above.
The operation is shown below:

2.6.1.3 Rule Configuration#

2.6.1.4 Request Service#

2.6.1.5 Consumption and display of Logging#

As each logging platform has differences, such as storage available clickhouse, ElasticSearch, etc., visualization has self-developed or open source Grafana, Kibana, etc..
Logging-RabbitMQ plugin uses RabbitMQ to decouple production and consumption, while outputting logs in json format, consumption and visualization require users to choose different technology stacks to achieve their own situation.

2.6.1.6 Panel Display#

Users can choose to visualize the implementation according to their own situation.
The following shows the effect of Grafana:
Grafana Sandbox Experience

3. How to disable plugin

  • In shenyu-admin --> BasicConfig --> Plugin --> loggingRabbitMQ set Status disable.