Jimy-Guo commented on issue #218: URL: https://github.com/apache/apisix-java-plugin-runner/issues/218#issuecomment-1342142123
> Possible errors I see. > > 1. the built jar does not contain your custom filter; > 2. 0.3.1-SNAPSHOT contains errors. > > I suggest you > > 1. use 0.4.0 (already released) > 2. try with [https://github.com/apache/apisix-java-plugin-runner/blob/main/docs/en/latest/installation-guide.md#install,](https://github.com/apache/apisix-java-plugin-runner/blob/main/docs/en/latest/installation-guide.md#install%EF%BC%8C) example: https://github.com/tzssangglass/java-plugin-runner-demo-1 我将https://github.com/tzssangglass/java-plugin-runner-demo-1的程序打包后,修改了以下地方的配置 java-plugin-runner-demo的application.yaml: ``` logging: level: root: debug cache.config: expired: ${APISIX_CONF_EXPIRE_TIME} capacity: 1000 socket: file: ${APISIX_LISTEN_ADDRESS} ``` pom.xml: ``` <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.1</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>demo</description> <properties> <java.version>11</java.version> <compiler.version>11</compiler.version> <spring-boot.version>2.7.1</spring-boot.version> </properties> <dependencies> <dependency> <groupId>org.apache.apisix</groupId> <artifactId>apisix-runner-starter</artifactId> <version>0.4.0</version> </dependency> <dependency> <groupId>org.apache.apisix</groupId> <artifactId>apisix-runner-plugin-sdk</artifactId> <version>0.4.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.6.8</version> </plugin> </plugins> </build> </project> ``` 使用的DockerFile为: ``` #进入文件后 #依赖镜像名称和ID FROM apache/apisix:2.15.1-debian #指定镜像创建者信息 MAINTAINER jimyguo #将宿主机的文件拷贝到容器的具体目录中。这里使用ADD,拷贝后自动解压,如果不需要解压,可以使用COPY ADD jdk-11.0.16.1_linux-x64_bin.tar.gz /jdk #ADD apache-apisix-java-plugin-runner-0.3.1-SNAPSHOT-bin.tar.gz /usr/local #RUN apt -y install openjdk-11-jdk #ADD apache-apisix-java-plugin-runner-0.4.0-bin.tar.gz /usr/local ADD demo-0.0.1-SNAPSHOT.jar /usr/local #ADD apisix-java-plugin-runner-0.4.0-SNAPSHOT-src.tgz /usr/local # ### 配置jdk环境 ENV JAVA_HOME /jdk/jdk-11.0.16.1 ENV PATH ${JAVA_HOME}/bin:$PATH ``` apisix的config.yaml: ``` ext-plugin: cmd: ['java', '-jar', '-Xmx4g', '-Xms4g', '/usr/local/demo-0.0.1-SNAPSHOT.jar'] ``` 路由上配置为: ``` "plugins": { "ext-plugin-pre-req": { "conf": [ { "name": "DemoFilter", "value": "{\"enable\":\"feature\"}" } ] }, ``` 配置完之后日志可见 ``` 2022/12/08 06:16:33 [warn] 57#57: *247 [lua] init.lua:913: 2022-12-08 06:16:33.047 DEBUG 58 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'demoApplication' , context: ngx.timer 2022/12/08 06:16:33 [warn] 57#57: *247 [lua] init.lua:913: 2022-12-08 06:16:33.049 DEBUG 58 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'demoFilter' , context: ngx.timer 2022/12/08 06:16:33 [warn] 57#57: *247 [lua] init.lua:913: 2022-12-08 06:16:33.061 DEBUG 58 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'a6HandlerConfiguration' , context: ngx.timer 2022/12/08 06:16:33 [warn] 57#57: *247 [lua] init.lua:913: 2022-12-08 06:16:33.062 DEBUG 58 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'applicationRunner' ``` 调用后可见 ``` 2022/12/08 06:16:33 [warn] 57#57: *247 [lua] init.lua:913: 2022-12-08 06:16:33.397 DEBUG 58 --- [ main] i.n.b.ByteBufUtil : -Dio.netty.threadLocalDirectBufferSize: 0 , context: ngx.timer 2022/12/08 06:16:33 [warn] 57#57: *247 [lua] init.lua:913: 2022-12-08 06:16:33.397 DEBUG 58 --- [ main] i.n.b.ByteBufUtil : -Dio.netty.maxThreadLocalCharBufferSize: 16384 , context: ngx.timer 2022/12/08 06:16:33 [warn] 57#57: *247 [lua] init.lua:913: 2022-12-08 06:16:33.419 WARN 58 --- [ main] o.a.a.p.r.s.ApplicationRunner : java runner is listening on the socket file: /usr/local/apisix/conf/apisix-1.sock , context: ngx.timer 127.0.0.1 - - [08/Dec/2022:06:20:34 +0000] 0.0.0.0:9080 "GET /apisix/admin/routes HTTP/1.1" 200 1734 0.002 "-" "curl/7.74.0" - - - "http://0.0.0.0:9080" 127.0.0.1 - - [08/Dec/2022:06:20:34 +0000] 0.0.0.0:9080 "GET /v1/admin/routes HTTP/1.1" 200 1734 0.005 "-" "curl/7.74.0" 127.0.0.1:9180 200 0.004 "http://0.0.0.0:9080/apisix/admin/routes" ``` 可见未打印logger.warn("DemoFilter is running");,需确定是还有什么地方漏了吗? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
