使用 spring-cloud-gateway 2.0.0.M5,我在配置文件(application.yml)中定义路由。我正在尝试通过调用 POST /application/gateway/refresh 来更新这些路由。
修改后的路由或新路由不会刷新,即使我看到(使用断点)实际执行了刷新例程。
当配置文件中定义路由时刷新应该起作用吗?我缺少什么吗?
用例是 spring 配置服务器中定义的路由。
我创建了一个 Feign 客户端 EmployeeServiceClient.java ,如下所示
EmployeeServiceClient.java
@FeignClient(name = "employeeclient", url = "https://internel.omnesys.org")
public interface EmployeeServiceClient {
@RequestMapping(method = RequestMethod.GET, value = "/v1/employees")
List<EmployeeDetails> getEmployeeDetails();
}
Run Code Online (Sandbox Code Playgroud)
员工详细信息.java
public class EmployeeDetails {
private Employee employee;
private String empId;
// getters and setters
}
Run Code Online (Sandbox Code Playgroud)
员工.java
public class Employee {
private String name;
private String firstName;
private String lastName;
private String city;
// getters and setters
}
Run Code Online (Sandbox Code Playgroud)
服务 https://internel.omnesys.org/v1/employees(这是由不同团队管理的 Intranet REST 服务)为我提供了如下所示的响应寿命
)}]',
[{"employee":{"name":"Emp1","firstName":"firstName1","lastName":"lastName1","city":"city1"},"empId":"empId123"},{"employee":{"name":"Emp2","firstName":"firstName2","lastName":"lastName2","city":"city2"},"empId":"empId456"}]
Run Code Online (Sandbox Code Playgroud)
我收到假装异常,因为服务响应)}]',在开头包含一个附加内容
我已要求服务团队删除这些无效字符,但他们说不可能删除它,因为它是为了其他要求而故意放置的,并要求我从我们这边处理它。
谁能帮我解决这个问题
我正在设置(Spring boot 2)Spring cloud zuul/网关并遇到超时问题。在阅读了官方文档并检查了类似的问题后,我不相信所提出的解决方案。
我使用以下类型的路由配置:
routes:
test-service:
path: /test-service/**
serviceId: test-service
Run Code Online (Sandbox Code Playgroud)
我认为这不是“url 路由”,所以我认为这些属性不适用:
zuul.host.connect-timeout-millis
zuul.host.connection-request-timeout-millis
zuul.host.socket-timeout-millis
Run Code Online (Sandbox Code Playgroud)
我尝试设置下面的属性,但 IntelliJ 指示这些属性“不存在”。这是 IDE 中的一个怪癖,还是这些属性仅在某些情况下存在/活动?
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds= 11000
hystrix.command.default.execution.timeout.enabled=false
ribbon.ConnectTimeout= 10000
ribbon.ReadTimeout: 10000
Run Code Online (Sandbox Code Playgroud)
例如,请参阅我的 bootstrap.yml 中的屏幕截图,其中仅建议其他属性:

默认情况下,带有此 Maven 依赖项的 Ribbon 和 hystrix 是否存在并处于活动状态?
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud) 我无法弄清楚如何测试使用 Avro 作为消息格式和(融合)架构注册表的 Spring Cloud Stream Kafka Streams 应用程序。
配置可能是这样的:
spring:
application:
name: shipping-service
cloud:
stream:
schema-registry-client:
endpoint: http://localhost:8081
kafka:
streams:
binder:
configuration:
application:
id: shipping-service
default:
key:
serde: org.apache.kafka.common.serialization.Serdes$IntegerSerde
schema:
registry:
url: ${spring.cloud.stream.schema-registry-client.endpoint}
value:
subject:
name:
strategy: io.confluent.kafka.serializers.subject.RecordNameStrategy
bindings:
input:
consumer:
valueSerde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
order:
consumer:
valueSerde: io.confluent.kafka.streams.serdes.avro.GenericAvroSerde
output:
producer:
valueSerde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
bindings:
input:
destination: customer
order:
destination: order
output:
destination: order
server:
port: 8086
logging:
level:
org.springframework.kafka.config: debug
Run Code Online (Sandbox Code Playgroud)
笔记:
我想关于 Kafka Broker,我应该使用 EmbeddedKafkaBroker bean,但如您所见,它还依赖于应该以某种方式模拟的模式注册表。如何?
apache-kafka spring-cloud spring-cloud-stream apache-kafka-streams spring-kafka
根据我的理解resilience4j.circuitbreaker.configs.<baseConfigName>,在 application.properties 中定义,CircuitBreakerRegistries使用自定义默认值创建新的
并创建引用注册表默认值resilience4j.circuitbreaker.instances.<instanceName>的实例以供使用CircuitBreakerresilience4j.circuitbreaker.instances.<myInstance>.base-config: <baseConfigName>
但是application.properties 是做什么resilience4j.circuitbreaker.backends.<backendName>用的?
如果后端是CircuitBreakerConfigs如何引用定义的配置(= CircuitBreakerRegistries)?
我如何将这些后端用于我在 application.properties 中定义的 CircuitBreaker 实例?
我使用 Spring Cloud Data Flow 设置一个读取 CSV 文件的流,使用自定义处理器对其进行转换并记录它:
stream create --name testsourcecsv --definition "file --mode=lines --directory=D:/toto/ --file.filename-pattern=adresses-28.csv --maxMessages=1000 | csvToMap --spring.cloud.stream.bindings.output.content-type=application/json | log --spring.cloud.stream.bindings.input.content-type=application/json" --deploy
Run Code Online (Sandbox Code Playgroud)
文件和 csvToMap 应用程序工作正常,但在日志应用程序中,对于每条记录,我都看到这种异常:
2019-12-03 11:32:46.500 ERROR 1328 --- [container-0-C-1] o.s.c.s.b.k.KafkaMessageChannelBinder$5 : Could not decode json type: adresses-28.csv for key: file_name
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'adresses': was expecting ('true', 'false' or 'null')
at [Source: (byte[])"adresses-28.csv"; line: 1, column: 10]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1804) ~[jackson-core-2.9.9.jar!/:2.9.9]
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:703) ~[jackson-core-2.9.9.jar!/:2.9.9]
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._reportInvalidToken(UTF8StreamJsonParser.java:3532) ~[jackson-core-2.9.9.jar!/:2.9.9]
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2627) ~[jackson-core-2.9.9.jar!/:2.9.9]
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:832) ~[jackson-core-2.9.9.jar!/:2.9.9]
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:729) ~[jackson-core-2.9.9.jar!/:2.9.9] …Run Code Online (Sandbox Code Playgroud) spring-cloud spring-cloud-stream spring-cloud-dataflow spring-cloud-stream-binder-kafka
我在 Spring Boot 中创建了多个微服务,它们与 zuul 代理进行通信。我的问题是请求花费了太多时间,我想测量从请求到达代理所花费的时间以及请求的时间从代理转发到我的微服务。有什么方法可以做到这一点吗?谢谢!
我创建了三个应用程序“spring cloud gateway(8081)”、“spring oauth2 auth server(8094)”和“spring oauth2 Resource server(8097)”。
\n\n当我想请求资源服务器时,首先我需要请求 gw,它转发到 oauth 服务器,然后我登录那里(oauth 也有 spring 安全层)。成功登录后,它会重定向到后台 gw 服务器,例如http://localhost:8081/login/oauth2/code/gateway?code=6ldKVF&state=0WvvWdTs8G_XchSTQKqgokua_XDVQziqVZ_VXLMqIS0%3D url。然后,屏幕上发生错误。
\n\n当我在身份验证服务器成功登录时,网关服务器控制台中有一个跟踪日志:
\n\n\n\n\n2020-01-17 17:52:11.825 跟踪 11336 --- [ctor-http-nio-4]\n oshttp.codec.json.Jackson2JsonDecoder :[21762c89] 已解码\n [{access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOls ib2F1dGgyLXJlc291cmNlIl0sInVzZXJfbmFtZSI6ImRnIiwic2NvcGUIOlsiY3VzdG9tX21vZCJdLCJleHAiOjE1NzkyNzI3NDEsImF1dGhvcml0aWVzIjpbIlJPTEVfQURNSU4iXSwianRpIjoiowu zYzQ2YTQtMDJiZi00MTgwLTg1ZTktMGJhOTM0MjBhYjg4IiwiY2xpZW50X2lkIjoiZmlyc3QtY2xpZW50In0.xdWGm420tvp2Rzq0AyCgOTcDuKvP- V6JFd76KmJJf7o,\n token_type=承载,\n refresh_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsib2F1dGgyLXJlc291cmNlIl0sInVzZXJfbmFtZSI6ImRnIiwic2NvcGUiOlsiY3Vz dG9tX21vZCJdLCJhdGkiOiI5ZTNjNDZhNC0wMmJmLTQxODAtODVLOS0wYmE5MzQyMGFiODgiLCJleHAiOjE1NzkyNzI3NTEsImF1dGhvcml0aWVzIjpbIlJPTEVfQURNSU4iXSwianRpIjoiYzeyNWexM2It MmMzYS00ZGM0LWJjODgtZDc4ZDk1ZTljNzQ5IiwiY2xpZW50X2lkIjoiZmlyc3QtY2xpZW50In0.KhRIy7wOH2IsswDZ_AIXVFdtu6JZqtiLBZGZIypeNRw,\n expires_in=9,scope=custom_mod,\n jti=9e3 c46a4-02bf-4180-85e9-0ba93420ab88}]
\n
当我解码以访问令牌 jwt 时,结果如下。
\n\n{\n"aud": [\n"oauth2-resource"\n],\n"user_name": "dg",\n"scope": [\n"custom_mod"\n],\n"exp": 1579272741,\n"authorities": [\n"ROLE_ADMIN"\n],\n"jti": "9e3c46a4-02bf-4180-85e9-0ba93420ab88",\n"client_id": "first-client"\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我想,我缺少一些在网关服务器或 oauth 服务器中实现的部分,但我找不到。因为当我尝试使用 okta 而不是我的自定义身份验证服务器时,没有错误。
\n\n网关应用程序.properties
\n\nserver.port=8081\nspring.security.oauth2.client.registration.gateway.client-id=first-client\nspring.security.oauth2.client.registration.gateway.client-secret=noonewilleverguess\nspring.security.oauth2.client.registration.gateway.authorization-grant-type=authorization_code\nspring.security.oauth2.client.registration.gateway.redirect-uri={baseUrl}/login/oauth2/code/{registrationId}\n\nspring.security.oauth2.client.provider.gateway.authorization-uri=http://localhost:8094/oauth/authorize\nspring.security.oauth2.client.provider.gateway.token-uri=http://localhost:8094/oauth/token?scope=custom_mod\nspring.security.oauth2.client.provider.gateway.user-info-uri=http://localhost:8094/userinfo\nspring.security.oauth2.client.provider.gateway.user-name-attribute=name\n\nlogging.level.root=trace\nRun Code Online (Sandbox Code Playgroud)\n\n这是屏幕错误消息:
\n\n\n1 月 17 日星期五 17:28:11 EET 2020 …
spring-security spring-security-oauth2 spring-cloud spring-oauth2 spring-cloud-gateway
我想为我的微服务应用程序创建一个网关服务,并添加 spring 云网关文档中提到的配置以禁用网关中的 CORS:
spring:
# GATEWAY CONFIG
cloud:
gateway:
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "*"
allowedMethods: "*"
Run Code Online (Sandbox Code Playgroud)
但我仍然收到 403 Forbidden Error。我的配置错了吗?
我正在使用 Spring Boot 云网关。Spring 版本是 2.3.4.RELEASE 我的 eureka 服务器运行良好,其他配置运行良好。但是当我要运行云网关时,Spring 会出现如下错误。
org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration'; nested exception is reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalArgumentException: Unable to find RoutePredicateFactory with name path
Run Code Online (Sandbox Code Playgroud)
我的云网关配置是这样的。
spring:
cloud:
gateway:
routes:
- id: sripy-client
uri: localhost:8080
predicates:
- path=/client/
application:
name: API-GATEWAY
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka/
instance:
hostname: localhost
server:
port: 8989
Run Code Online (Sandbox Code Playgroud)
和 porm.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.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from …Run Code Online (Sandbox Code Playgroud) spring-cloud ×10
spring-boot ×5
java ×4
netflix-zuul ×2
spring ×2
apache-kafka ×1
feign ×1
gateway ×1
resilience4j ×1
spring-cloud-stream-binder-kafka ×1
spring-kafka ×1