我正在处理 Spring cloud 合同文档,我看到了Spring cloud 文档依赖的评论,想知道这到底是什么 <!-- If you're adding this dependency explicitly you have to
add it *BEFORE* the Release Train BOM-->
我知道我们可以通过提供 url Ex 来强制 FeignClient 使用 OkHttp 而不是 Ribbon。 @FeignClient(url="serviceId", name="serviceId")
即使只提供了名称,我也希望使用 OkHttpClient。前任。@FeignClient(name="serviceId")
根据 spring cloud 文档“如果启用 Ribbon,则它是 LoadBalancerFeignClient,否则使用默认的 feign 客户端。”
如何禁用功能区以便使用默认的伪装客户端。
spring-cloud netflix-feign spring-cloud-feign feign spring-cloud-netflix
我有一个监控应用程序,其中正在运行固定速率任务。这是拉入用 Consul 配置的配置参数。我想引入更新的配置,所以我添加了@RefreshScope。但是,一旦我更新 Consul 上的配置值,fixedRate 任务就会停止运行。
@Service
@RefreshScope
public class MonitorService {
@Autowired
private AppConfig appConfig;
@PostConstruct
public void postConstRun() {
System.out.println(appConfig.getMonitorConfig());
}
@Scheduled(fixedRate = 1000)
public void scheduledMonitorScan() {
System.out.println("MonitorConfig:" + appConfig.getMonitorConfig());
}
}
Run Code Online (Sandbox Code Playgroud)
AppConfig 类只有一个 String 参数:
@Configuration
@Getter
@Setter
public class AppConfig {
@Value("${monitor-config:default value}")
private String monitorConfig;
}
Run Code Online (Sandbox Code Playgroud)
一旦我更新领事中的值,计划任务就会停止运行(在 sheduledMonitorScan 方法中显示)并停止显示。
使用 Spring for Apache Kafka 或 Spring AMQP,我可以实现消息发布/订阅。Spring Cloud Bus使用kafka/rabbitmq做大致相同的事情,它们之间有什么区别?
我正在开发Microservices with Spring Boot 2.0, Eureka and Spring Cloud一个参考:https://piotrminkowski.wordpress.com/2018/04/26/quick-guide-to-microservices-with-spring-boot-2-0-eureka-and-spring-cloud/.在这个例子中,我开发config-service与spring-boot-starter-parent版本2.0.4.RELEASE.
当我只是运行此代码时,我得到以下错误.没有提到设置本地git或使用远程git的步骤.有人可以指导我吗?
错误:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
23:04:07.774 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
at com.prateek.ConfigServiceApplication.main(ConfigServiceApplication.java:12)
Caused by: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Spring Vault 提供集中式服务,为我们的微服务生态系统提供存储和检索凭证信息的功能。然而,我们的组织目前使用 cyber-ark 来集中凭证,所以我正在寻找的是构建一个基于 Spring Vault 的抽象服务,并为 Harshicorp Vault 使用 cyber-arkas 存储引擎。
cyber-ark spring-boot spring-cloud hashicorp-vault spring-vault
我正在构建一个使用 AWS SQS 队列的 Spring Boot 应用程序。我能够使用队列,但是我似乎无法使用多个并发消费者这样做。
从命令行运行时mvn spring-boot:run,它会连接到 SQS 并将一次接收一条消息。侦听器方法有额外的代码,这会导致几秒钟的延迟,在此期间我希望接收和处理第二条消息。
就好像没有使用配置一样。
pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-messaging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.419</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws</artifactId>
<version>2.0.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin> …Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring Cloud Dataflow 并创建了一个包含作业的 Spring Cloud 任务。该作业有一个名为last_modified_date 的参数,该参数是可选的。在代码中,我指定了在last_modified_date为null的情况下采用哪个日期,即它尚未作为参数传递。问题是,如果对于该作业的一个实例,我传递了last_modified_date,但对于下一个实例,我没有传递,它会选择最后一次执行中的日期,而不是将其作为 null 传递并从代码中获取它。
@Component
@StepScope
public class SalesforceAdvertiserLoadTasklet implements Tasklet {
@Value("#{jobParameters['last_modified_date']}")
protected Date lastModifiedDate;
private static final Logger logger =
LoggerFactory.getLogger(SalesforceAdvertiserLoadTasklet.class);
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
if(lastModifiedDate == null) {
lastModifiedDate =
Date.from(LocalDate.now().minusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant());
}
logger.info("In Method: runSalesforceAdvertiserLoadJob launch started on last_modified_date {}",
lastModifiedDate);
logger.info("Getting advertisers from SalesForce");
try {
getAdvertisersFromSalesforceAndAddtoDb();
} catch (JsonSyntaxException | IOException | ParseException e) {
logger.error("ERROR--> {}", e.getMessage());
}
return RepeatStatus.FINISHED;
} …Run Code Online (Sandbox Code Playgroud) spring batch-processing spring-batch spring-boot spring-cloud
有没有办法配置 opentracing-spring-jaeger-cloud-starter 来处理除 Uber-Trace-Id 之外的任何其他标头?我的 kubernetes 集群中有 Traefik 作为入口。Traefik 可以配置为更改 traceContextHeaderName。默认值为“uber-trace-id”。当我将其更改为某种自定义时,服务之间没有连接(我的意思是跨度连接)。我相信 opentracing 仅适用于 Uber-Trace-Id。有没有办法配置它?
我在 minikube 中使用 Traefik 作为入口进行测试。然后所有请求都转到 spring-cloud-gateway 并传播到服务。
感谢帮助!
我已经阅读了整个文档、教程 [1],并在源代码中花费了几个小时,但我仍然不明白如何配置负载均衡器,特别是如果我不使用魔术注释的话。
我有以下配置:
@Configuration
public class AppConfig {
public static final String SERVICE_ID = "service";
@Primary
@Bean
public ServiceInstanceListSupplier serviceInstanceListSupplier() {
return ServiceInstanceListSuppliers.from(SERVICE_ID,
new DefaultServiceInstance(SERVICE_ID + "1", SERVICE_ID, "localhost", 8886, false),
new DefaultServiceInstance(SERVICE_ID + "2", SERVICE_ID, "localhost", 8887, false));
}
@Bean
public LoadBalancerClientFactory loadBalancerClientFactory() {
return new LoadBalancerClientFactory();
}
@Bean
public ReactorLoadBalancerExchangeFilterFunction loadBalancerExchangeFilterFunction(LoadBalancerProperties properties) {
return new ReactorLoadBalancerExchangeFilterFunction(loadBalancerClientFactory(), properties);
}
}
Run Code Online (Sandbox Code Playgroud)
并使用 beanloadBalancerExchangeFilterFunction作为:
WebClient.builder()
.baseUrl("http://service/test-consumer")
.filter(lbFunction)
.build();
Run Code Online (Sandbox Code Playgroud)
它有效。问题是,无论我使用什么主机名,它都可以工作。因此,如果我将主机名“service”替换为我喜欢的任何工作,我仍将向 localhost:8886 或 localhost:8887 发送数据。
有人可以解释一下 serviceId 的作用是什么以及它如何与 DefaultServiceInstance …
spring-cloud ×10
spring ×3
spring-boot ×3
java ×2
amazon-sqs ×1
cyber-ark ×1
dependencies ×1
feign ×1
jaeger ×1
opentracing ×1
pom.xml ×1
spring-batch ×1
spring-vault ×1
traefik ×1