apache / shenyu

Apache ShenYu is a Java native API Gateway for service proxy, protocol conversion and API governance.
https://shenyu.apache.org/
Apache License 2.0
8.44k stars 2.93k forks source link

problem with shenyu-bootstrap #1909

Closed Romic77 closed 3 years ago

Romic77 commented 3 years ago

question: git clone study-shenyu

image image

applicaiton.yml

  port: 8060
spring:
  application:
    name: shenyu-study
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848

shenyu:
  client:
    registerType: nacos #zookeeper #etcd #nacos #consul
    serverLists: localhost:8848 #localhost:2181 #http://localhost:2379 #localhost:8848
    props:
      contextPath: /shenyu-study
      port: 8060
      nacosNameSpace: ShenyuRegisterCenter

logging:
  level:
    root: info
    org.apache.shenyu: debug

pom.yml

<?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.2.10.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.example</groupId>
    <artifactId>study-shenyu</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>study-shenyu</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <spring-cloud.version>2.2.0.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.shenyu</groupId>
            <artifactId>shenyu-spring-boot-starter-client-springcloud</artifactId>
            <version>2.4.0-SNAPSHOT</version>
        </dependency>
        <!--spring boot的核心启动器-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>2.2.1.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-commons</artifactId>
            <version>${spring-cloud.version}</version>
        </dependency>
        <!--<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>${spring-cloud.version}</version>
        </dependency>-->
    </dependencies>

</project>

controller

package com.example.studyshenyu.controller;

import org.apache.shenyu.client.springcloud.annotation.ShenyuSpringCloudClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
@ShenyuSpringCloudClient(path = "/test/**")
public class HelloController {

    @GetMapping("/hello")
    public String findByUserId() {
       return "hello shenyu";
    }
}

postman

What's the problem?

image

KevinClair commented 3 years ago

Hello @rom1c77 , you can use module shenyu-examples-springcloud and try it again.

Romic77 commented 3 years ago

Hello @rom1c77 , you can use module shenyu-examples-springcloud and try it again.

emm,shenyu-examples-springcloud use eureka. our project want use nacos...

midnight2104 commented 3 years ago

hello, do you add dependency to shenyu-admin? you can refer to Application Client Access Config

KevinClair commented 3 years ago

Hello @rom1c77 , you can use module shenyu-examples-springcloud and try it again.

emm,shenyu-examples-springcloud use eureka. our project want use nacos...

That's fine, you can update module's dependency.

Romic77 commented 3 years ago

shenyu-admin application.yml

# 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
#
#     http://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.

server:
  port: 9095
  address: 0.0.0.0

spring:
  profiles:
    active: mysql
  thymeleaf:
    cache: true
    encoding: utf-8
    enabled: true
    prefix: classpath:/static/
    suffix: .html
  datasource:
    url: jdbc:mysql://localhost:3306/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver

mybatis:
  config-location: classpath:/mybatis/mybatis-config.xml
  mapper-locations: classpath:/mappers/*.xml

shenyu:
  register:
    registerType: nacos #http #zookeeper #etcd #nacos #consul
    serverLists: localhost:8848 #localhost:2181 #http://localhost:2379 #localhost:8848
    props:
      sessionTimeout: 5000
      connectionTimeout: 2000
      checked: true
      zombieCheckTimes: 5
      scheduledTime: 10
      nacosNameSpace: ShenyuRegisterCenter
  database:
    dialect: mysql
    init_script: "META-INF/schema.sql"
    init_enable: true
  sync:
#    websocket:
#      enabled: true
#      zookeeper:
#        url: localhost:2181
#        sessionTimeout: 5000
#        connectionTimeout: 2000
#      http:
#        enabled: true
      nacos:
        url: localhost:8848
        namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
        username:
        password:
        acm:
          enabled: false
          endpoint: acm.aliyun.com
          namespace:
          accessKey:
          secretKey:
#    etcd:
#      url: http://localhost:2379
#    consul:
#      url: http://localhost:8500
  aes:
    secret:
      key: 2095132720951327
      iv: 6075877187097700
  ldap:
    enabled: false
    url: ldap://xxxx:xxx
    bind-dn: cn=xxx,dc=xxx,dc=xxx
    password: xxxx
    base-dn: ou=xxx,dc=xxx,dc=xxx
    object-class: person
    login-field: cn
  jwt:
    expired-seconds: 86400000
  shiro:
    white-list:
      - /
      - /favicon.*
      - /static/**
      - /index**
      - /plugin
      - /platform/**
      - /websocket
      - /configs/**
      - /shenyu-client/**
      - /error
      - /actuator/health
      - /swagger-ui.html
      - /webjars/**
      - /swagger-resources/**
      - /v2/api-docs
      - /csrf
  swagger:
    enable: true

logging:
  level:
    root: info
    org.springframework.boot: info
    org.apache.ibatis: info
    org.apache.shenyu.bonuspoint: info
    org.apache.shenyu.lottery: info
    org.apache.shenyu: info

shenyu-bootstrap application-local.yml

# 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
#
#     http://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.

server:
  port: 9195
  address: 0.0.0.0

spring:
  main:
    allow-bean-definition-overriding: true
  application:
    name: shenyu-bootstrap
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
#  security:
#    oauth2:
#      client:
#        registration:
#          <your client-registration-id>:
#            client-id: <your client-id>
#            client-secret: <your client-secret>
#        provider:
#          <your client-registration-id>:
#            authorization-uri: <your authorization-uri>
#            token-uri: <your access-token-uri>
#            user-info-uri: <your user-info-uri>
#            jwk-set-uri: <your jwk-set-uri>

management:
  health:
    defaults:
      enabled: false

shenyu:
  file:
    enabled: true
  cross:
    enabled: true
  dubbo:
    parameter: multi
  sync:
#    websocket:
#      urls: ws://localhost:9095/websocket
#    zookeeper:
#      url: localhost:2181
#      sessionTimeout: 5000
#      connectionTimeout: 2000
#    http:
#      url: http://localhost:9095
    nacos:
      url: localhost:8848
      namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
      username:
      password:
      acm:
        enabled: false
        endpoint: acm.aliyun.com
        namespace:
        accessKey:
        secretKey:
#    etcd:
#      url: http://localhost:2379
#    consul:
#      url: http://localhost:8500
#      waitTime: 1000
#      watchDelay: 1000
  exclude:
    enabled: false
    paths:
      - /favicon.ico

#eureka:
#  client:
#    serviceUrl:
#      defaultZone: http://localhost:8761/eureka/
#  instance:
#    prefer-ip-address: true

logging:
  level:
    root: info
    org.springframework.boot: info
    org.apache.ibatis: info
    org.apache.shenyu.bonuspoint: info
    org.apache.shenyu.lottery: info
    org.apache.shenyu: info
Romic77 commented 3 years ago

@midnight2104

Romic77 commented 3 years ago
  1. plz git clone git@github.com:rom1c77/incubator-shenyu.git & git clone git@github.com:rom1c77/study-shenyu.git
  2. update mysql username/passwordashenyu-admin application.yml
  3. run ShenyuAdminBootstrap & ShenyuAdminBootstrap & StudyShenyuApplication

question: SelectorList and RulesList hava data,but curl http://localhost:9195/springcloud/test/hello unsuccessful. image image

help me resolve this problem,plz.

thanks for you very much

Romic77 commented 3 years ago

Hello @rom1c77 , you can use module shenyu-examples-springcloud and try it again.

emm,shenyu-examples-springcloud use eureka. our project want use nacos...

That's fine, you can update module's dependency.

It's the same problem. Please, I was desperate .

KevinClair commented 3 years ago

Hello @rom1c77 , I try it successfully with shenyu-examples-springcloud module. Maybe you forgot to open the plugin springCloud in Plugin.

image

Romic77 commented 3 years ago

Hello @rom1c77 , I try it successfully with shenyu-examples-springcloud module. Maybe you forgot to open the plugin springCloud in Plugin.

image

i'm sure open this

Romic77 commented 3 years ago

Hello @rom1c77 , I try it successfully with shenyu-examples-springcloud module. Maybe you forgot to open the plugin springCloud in Plugin.

image

image

midnight2104 commented 3 years ago

pls use websocket for data sync, it's recommend Data Synchronization Config

KevinClair commented 3 years ago
midnight2104 commented 3 years ago

hello, I use nacso as register cneter that it is successfull. here is my config:

jdk : 14 shenyu: 2.4.0 nacos: 2.0.3

shneyu-admin:

        <dependency>
            <groupId>org.apache.shenyu</groupId>
            <artifactId>shenyu-register-server-nacos</artifactId>
            <version>${project.version}</version>
        </dependency>

server:
  port: 9095
  address: 0.0.0.0

spring:
  profiles:
    # active: h2
  thymeleaf:
    cache: true
    encoding: utf-8
    enabled: true
    prefix: classpath:/static/
    suffix: .html
  datasource:
    url: jdbc:mysql://localhost:3306/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: 
    driver-class-name: com.mysql.jdbc.Driver

mybatis:
  config-location: classpath:/mybatis/mybatis-config.xml
  mapper-locations: classpath:/mappers/*.xml

shenyu:
  register:
    registerType: nacos #http #http #zookeeper #etcd #nacos #consul
    serverLists: localhost:8848 #localhost:2181 #http://localhost:2379 #localhost:8848
    props:
      sessionTimeout: 5000
      connectionTimeout: 2000
      checked: true
      zombieCheckTimes: 5
      scheduledTime: 10
      nacosNameSpace: ShenyuRegisterCenter
  database:
    dialect: mysql
    init_script: "META-INF/schema.sql"
    init_enable: true
  sync:
    websocket:
      enabled: true
#      zookeeper:
#          url: localhost:2181
#          sessionTimeout: 5000
#          connectionTimeout: 2000
#      http:
#        enabled: true
  #    nacos:
  #      url: localhost:8848
  #      namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
  #      username:
  #      password:
  #      acm:
  #        enabled: false
  #        endpoint: acm.aliyun.com
  #        namespace:
  #        accessKey:
  #        secretKey:
#    etcd:
#      url: http://localhost:2379
#    consul:
#      url: http://localhost:8500
  aes:
    secret:
      key: 2095132720951327
      iv: 6075877187097700
  ldap:
    enabled: false
    url: ldap://xxxx:xxx
    bind-dn: cn=xxx,dc=xxx,dc=xxx
    password: xxxx
    base-dn: ou=xxx,dc=xxx,dc=xxx
    object-class: person
    login-field: cn
  jwt:
    key: 2095132720951327
  shiro:
    white-list:
      - /
      - /favicon.*
      - /static/**
      - /index**
      - /plugin
      - /platform/**
      - /websocket
      - /configs/**
      - /shenyu-client/**
      - /error
      - /actuator/health
      - /swagger-ui.html
      - /webjars/**
      - /swagger-resources/**
      - /v2/api-docs
      - /csrf
  swagger:
    enable: true

logging:
  level:
    root: info
    org.springframework.boot: info
    org.apache.ibatis: info
    org.apache.shenyu.bonuspoint: info
    org.apache.shenyu.lottery: info
    org.apache.shenyu: info

shenyu-bootstrap:


server:
  port: 9195
  address: 0.0.0.0

spring:
   main:
     allow-bean-definition-overriding: true
   application:
    name: shenyu-bootstrap
   cloud:
    nacos:
       discovery:
          server-addr: 127.0.0.1:8848
#   security:
#      oauth2:
#        client:
#          registration:
#            <your client-registration-id>:
#              client-id: <your client-id>
#              client-secret: <your client-secret>
#          provider:
#            <your client-registration-id>:
#              authorization-uri: <your authorization-uri>
#              token-uri: <your access-token-uri>
#              user-info-uri: <your user-info-uri>
#              jwk-set-uri: <your jwk-set-uri>

management:
  health:
    defaults:
      enabled: false

shenyu:
    file:
      enabled: true
    cross:
      enabled: true
    dubbo :
      parameter: multi
    sync:
        websocket :
             urls: ws://localhost:9095/websocket
#        zookeeper:
#             url: localhost:2181
#             sessionTimeout: 5000
#             connectionTimeout: 2000
#        http:
#             url : http://localhost:9095
#        nacos:
#          url: localhost:8848
#          namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
#          username:
#          password:
#          acm:
#            enabled: false
#            endpoint: acm.aliyun.com
#            namespace:
#            accessKey:
#            secretKey:
#       etcd:
#         url: http://localhost:2379
#      consul:
#        url: http://localhost:8500
#        waitTime: 1000
#        watchDelay: 1000
    exclude:
      enabled: false
      paths:
        - /favicon.ico

#eureka:
#  client:
#    serviceUrl:
#      defaultZone: http://localhost:8761/eureka/
#  instance:
#    prefer-ip-address: true

logging:
    level:
        root: info
        org.springframework.boot: info
        org.apache.ibatis: info
        org.apache.shenyu.bonuspoint: info
        org.apache.shenyu.lottery: info
        org.apache.shenyu: info
 <!--shenyu springCloud plugin start-->
       <dependency>
            <groupId>org.apache.shenyu</groupId>
            <artifactId>shenyu-spring-boot-starter-plugin-springcloud</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.shenyu</groupId>
            <artifactId>shenyu-spring-boot-starter-plugin-httpclient</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-commons</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>

        <!-- springCloud if you config register center is nacos please dependency this-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>2.1.0.RELEASE</version>
        </dependency>

shenyu-example-springcloud


server:
  port: 8884
  address: 0.0.0.0

spring:
  application:
    name: springCloud-test
  cloud:
    nacos:
      discovery:
          server-addr: 127.0.0.1:8848

springCloud-test:
  ribbon.NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule

#eureka:
#  client:
#    serviceUrl:
#      defaultZone:  http://localhost:8761/eureka/
#  instance:
#    prefer-ip-address: true

shenyu:
  client:
    registerType: nacos #zookeeper #etcd #nacos #consul
    serverLists: localhost:8848 #localhost:2181 #http://localhost:2379 #localhost:8848
    props:
      contextPath: /springcloud
      port: 8884
      nacosNameSpace: ShenyuRegisterCenter

logging:
  level:
    root: info
    org.apache.shenyu: debug
        <dependency>
            <groupId>org.apache.shenyu</groupId>
            <artifactId>shenyu-spring-boot-starter-client-springcloud</artifactId>
            <version>${shenyu.version}</version>
        </dependency>

  <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>2.1.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.apache.shenyu</groupId>
            <artifactId>shenyu-register-client-nacos</artifactId>
            <version>${shenyu.version}</version>
        </dependency>

The above configuration can be successfully started and registered. Then you need to open springcloud plugin in shenyu background sysytem, you can access.

http://localhost:9195/springcloud/order/findById?id=100 { "id": "100", "name": "hello world spring cloud findById" }

Romic77 commented 3 years ago

@midnight2104 @KevinClair thanks

mysql dirty data cause serviceId = null.
debug find this and drop shenyu schema.
successfully It's my fault

image