|
| 1 | +--- |
| 2 | +title: Installation |
| 3 | +keywords: |
| 4 | +- apisix-java-plugin-runner |
| 5 | +- Installation |
| 6 | +description: This document explains how to installation and use apisix-java-plugin-runner. |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +<!-- |
| 11 | +# |
| 12 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 13 | +# contributor license agreements. See the NOTICE file distributed with |
| 14 | +# this work for additional information regarding copyright ownership. |
| 15 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 16 | +# (the "License"); you may not use this file except in compliance with |
| 17 | +# the License. You may obtain a copy of the License at |
| 18 | +# |
| 19 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 20 | +# |
| 21 | +# Unless required by applicable law or agreed to in writing, software |
| 22 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 23 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 24 | +# See the License for the specific language governing permissions and |
| 25 | +# limitations under the License. |
| 26 | +# |
| 27 | +--> |
| 28 | + |
| 29 | +## Overview |
| 30 | + |
| 31 | +This document explains how to install apisix-java-plugin-runner. |
| 32 | + |
| 33 | +Prerequisites |
| 34 | +------------- |
| 35 | + |
| 36 | +* JDK 11 |
| 37 | +* APISIX 2.15.0 |
| 38 | +* Refer to [Debug](how-it-works.md#debug) to build the debug environment. |
| 39 | + |
| 40 | +Install |
| 41 | +------- |
| 42 | + |
| 43 | +1. Create a simple web application with Spring Boot, and choose Maven as the build tool. |
| 44 | + |
| 45 | +2. Add the apisix-java-plugin-runner dependency in your POM, like: |
| 46 | + |
| 47 | +```xml |
| 48 | +<dependency> |
| 49 | + <groupId>org.apache.apisix</groupId> |
| 50 | + <artifactId>apisix-runner-starter</artifactId> |
| 51 | + <version>0.3.0</version> |
| 52 | +</dependency> |
| 53 | +``` |
| 54 | + |
| 55 | +3. Configuring the scan package path |
| 56 | + |
| 57 | +```xml |
| 58 | + |
| 59 | +```java |
| 60 | +@SpringBootApplication(scanBasePackages = {"your-filter's-package-name","org.apache.apisix.plugin.runner"}) |
| 61 | +``` |
| 62 | + |
| 63 | +4. Excluding the default logging framework |
| 64 | + |
| 65 | +To prevent multiple slf4j bindings, exclude the `logback-classic` and `log4j-to-slf4j` in `pom.xml`, like: |
| 66 | + |
| 67 | +```xml |
| 68 | +<dependency> |
| 69 | + <groupId>org.springframework.boot</groupId> |
| 70 | + <artifactId>spring-boot-starter</artifactId> |
| 71 | + <exclusions> |
| 72 | + <exclusion> |
| 73 | + <groupId>ch.qos.logback</groupId> |
| 74 | + <artifactId>logback-classic</artifactId> |
| 75 | + </exclusion> |
| 76 | + <exclusion> |
| 77 | + <groupId>org.apache.logging.log4j</groupId> |
| 78 | + <artifactId>log4j-to-slf4j</artifactId> |
| 79 | + </exclusion> |
| 80 | + </exclusions> |
| 81 | +</dependency> |
| 82 | +``` |
| 83 | + |
| 84 | +5. Configuring the address for Unix Domain Socket communication with APISIX |
| 85 | + |
| 86 | +```properties |
| 87 | +socket.file = /tmp/runner.sock |
| 88 | +``` |
| 89 | + |
| 90 | +6. Implementing the `PluginFilter` interface |
| 91 | + |
| 92 | +When you write your custom plugins, you need to implement the `PluginFilter` interface and |
| 93 | +inject filters into Spring Boot's object lifecycle management using `@Component`. |
| 94 | + |
| 95 | +code example: |
| 96 | + |
| 97 | +```java |
| 98 | +@Component |
| 99 | +public class RewriteRequestDemoFilter implements PluginFilter { |
| 100 | + ...... |
| 101 | + implementing functions |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +You can refer to [development](./development.md) to learn how to write custom plugins. |
| 106 | + |
| 107 | +Demo |
| 108 | +------- |
| 109 | + |
| 110 | +A Demo Project that work with apisix-java-plugin-runner and custom filters |
| 111 | +can be found at: [java-plugin-runner-demo](https://github.com/tzssangglass/java-plugin-runner-demo-1). |
0 commit comments