您能否建议一下,当控件到达 catch 块时,如何停止发送到我的第三个 kafka 主题,当前消息被发送到错误主题以及正常处理时应发送到的主题。一段代码如下:
@Component
public class Abc {
private final StreamBridge streamBridge;
public Abc (StreamBridge streamBridge)
this.streamBridge = streamBridge;
@Bean
public Function<KStream<String, KafkaClass>, KStream<String,KafkaClass>> hiProcess() {
return input -> input.map((key,value) -> {
try{
KafkaClass stream = processFunction();
}
catch(Exception e) {
Message<KakfaClass> mess = MessageBuilder.withPayload(value).build();
streamBridge.send("errProcess-out-0". mess);
}
return new KeyValue<>(key, stream);
})
}
}
Run Code Online (Sandbox Code Playgroud) apache-kafka spring-cloud spring-cloud-stream apache-kafka-streams spring-kafka
我在 k8s 集群中部署了一个 Spring Boot 应用程序(一组服务)。对于微米指标,我需要动态获取此应用程序运行的命名空间,以便我可以将其添加为指标中的标记。以下是我的自定义标签创建 bean
@Bean
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
return registry -> {
String hostname = getHostName();
registry.config().commonTags(TAG_NAME_INSTANCE,hostname);
final String applicationName = environment.getProperty(SPRING_BOOT_APPLICATION_NAME_PROPERTY_KEY);
registry.config().commonTags(TAG_NAME_APPLICATION, applicationName);
registry.config().commonTags(TAG_NAME_APP, applicationName);
registry.config().commonTags(TAG_NAME_KUBE_NAME_SPACE, getKubeNamespace());
};
Run Code Online (Sandbox Code Playgroud)
}
当前getKubeNamespace返回硬编码值。我如何获取此 Pod 正在运行哪个命名空间?
我们正在使用 spring-cloud 来读取我们应用程序的配置。我们在 application.yaml 中有类似的结构
spring:
cloud:
consul:
host: consul_host
port: 8500
Run Code Online (Sandbox Code Playgroud)
我们想为 consul 启用 ACL。所以我们需要通过consul token来通过 spring 读取配置。如何在 application.yaml 中指定 consul 令牌
我构建了一个 spring 云服务,包含 eureka、user-service(spring-data-rest user api) 和一个 feign-client 服务。
在假客户端:
@FeignClient("useraccount")
public interface UserFeign {
@RequestMapping(method=RequestMethod.POST,value="/users",consumes = "application/json")
void createUser(@RequestBody User user);
@RequestMapping(method=RequestMethod.DELETE,value="/users/{id}")
void delById (@PathVariable("id") String id);
Run Code Online (Sandbox Code Playgroud)
我想通过调用 user-service api 在 feign-client 中实现删除和存储用户。所以,我创建了一个休息控制器(js 向他们传输数据):
@Autowired
private UserFeign userFeign;
//save controller
@RequestMapping(method = RequestMethod.POST, value = "/property/register")
public ResponseEntity<?> createUser(@RequestBody User user) {
userSaveFeign.createUser(user);
return ResponseEntity.ok();
}
// and delete controller
@RequestMapping(method = RequestMethod.DELETE, value = "/property/{id}")
public String hello(@PathVariable("id") String id){
userSaveFeign.delById(id);
}
return "hello";
}
Run Code Online (Sandbox Code Playgroud)
但它总是遇到错误:
2016-04-16 20:05:41.162 …Run Code Online (Sandbox Code Playgroud) 在Jhipster中,文档说明:
在微服务架构中生成实体
如果您选择从微服务生成实体,则需要在本地计算机上输入此微服务的路径,然后JHipster将在网关上生成前端代码.
不能说我有多个网关.这是否意味着我有一个共同的微服务应用程序.我创建微服务应用程序实体然后在每个将使用此服务的网关中运行生成器?
这是发电机的意图吗?
是否有可能或解决方法告诉Spring Config Server从自身获取配置?我有一些针对所有Spring Boot应用程序的通用配置,具体取决于配置文件,并且我希望配置服务器能够不复制粘贴地访问它们。
我很难配置我的Spring Boot应用程序以通过Spring-Cloud-Connectors连接到提供Config-Server的PWS(Pivotal Web Services).
在manifest.yml中,配置服务器绑定到应用程序,相应的VCAP_SERVICES条目正确反映了该应用程序:
applications:
- name: edge-service-webapp-myapp
services:
- infrastructure-config-server
memory: 512M
env:
TRUST_CERTS: api.run.pivotal.io
SPRING_PROFILES_DEFAULT: cloud
instances: 1
host: edge-service-webapp-myapp
domain: cfapps.io
buildpack: java_buildpack
{
"VCAP_SERVICES": {
"p-config-server": [
{
"credentials": {
"access_token_uri": "https://p-spring-cloud-services.uaa.run.pivotal.io/oauth/token",
"client_id": "p-config-server-84d66ea6-ebc6-xxx",
"client_secret": "***",
"uri": "https://config-b4320676-xxx.cfapps.io"
}, ...
}
Run Code Online (Sandbox Code Playgroud)
该应用程序使用spring-boot-starter-parent 1.5.2.RELEASE,spring-cloud-dependencies Camden.SR5和spring-cloud-services-dependencies 1.4.1.RELEASE构建.此外,我使用spring-cloud-starter-config和spring-boot-starter-cloud-connectors作为显式依赖项.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.pivotal.spring.cloud</groupId>
<artifactId>spring-cloud-services-dependencies</artifactId>
<version>1.4.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
....
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cloud-connectors</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId> …Run Code Online (Sandbox Code Playgroud) spring cloud-foundry spring-boot spring-cloud pivotal-cloud-foundry
我想添加一个自定义错误Zuul过滤器,并希望确保SendErrorFilter不执行.我看了几个github链接,包括Spring-cloud/spring-cloud-netflix和各种堆栈溢出问题: -
我的代码如下 -
public class CustomErrorFilter extends ZuulFilter {
private static final Logger LOG = LoggerFactory.getLogger(CustomErrorFilter.class);
@Override
public String filterType() {
return "post";
}
@Override
public int filterOrder() {
return -1;
}
@Override
public boolean shouldFilter() {
RequestContext ctx=RequestContext.getCurrentContext();
if(ctx.getThrowable()!=null)
return true;
else
return false;
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
ctx.setThrowable(null); // response is not returned unless
throwable is set to null.
ctx.remove("error.status_code");
ctx.setResponseBody(“Error”);
ctx.getResponse().setContentType("text/plain");
ctx.setResponseStatusCode(400); …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring Cloud来创建微服务架构.
我使用的是Spring Cloud中的以下功能
现在让我们说如果我有100个微服务,那么我们需要100个服务器来维护每个微服务.所以我想用Kubernetes通过在一个单独的泊坞窗容器部署每个微服务,所以现在因为Kubernetes照顾microserivice健康检查,自动缩放,负载平衡,所以我需要再次使用丝带,尤里卡和Zuul来解决这个问题.
任何人都可以帮我这个
1.5.13.RELEASEEdgware.SR3 我的配置中的一些相关属性:
feign.hystrix.enabled=true
eureka.client.fetch-registry=true
spring.cloud.service-registry.auto-registration.enabled=true
service1.ribbon.listOfServers=https://www.google.com
Run Code Online (Sandbox Code Playgroud)
我有一个应用程序,可以使用伪装客户端与其他3种服务进行通信。其中的两个是通过Eureka服务发现而发现的。这些运作良好。最终服务是具有单个静态主机名的外部服务,我不希望通过Eureka解决此问题。由于我确实希望Eureka可以使用其中的两项服务,因此我希望启用Eureka。
对于最终服务,我尝试将添加service1.ribbon.listOfServers=https://www.google.com到中application.properties,但是在调用伪客户端时在运行时会遇到以下错误:
路径为[]的Servlet [dispatcherServlet]的Servlet.service()引发异常[请求处理失败;嵌套的异常是com.netflix.hystrix.exception.HystrixRuntimeException:Service1Client#test()失败,并且没有可用的备用。定价_1 | com.netflix.client.ClientException:负载均衡器没有可供客户端使用的服务器:service1Price_1 | 在com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:483)〜[ribbon-loadbalancer-2.2.5.jar!/:2.2.5]
我的客户端配置如下:
@FeignClient("service1")
public interface Service1Client {
@GetMapping(value = "/")
String test();
}
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的任何建议。
根据我所了解的功能区的精神,它是充当客户端负载平衡器,在我的情况下,没有任何负载平衡(我有一个固定的静态主机名,该主机名在DNS中返回单个A记录)。Ribbon实际上感觉像是一个不必要的组件-我真正想要的是Feign客户端,因为我喜欢这样一个事实,即它抽象了较低级别的HTTP请求和对象序列化。因此,我想一个替代的后续问题是,我可以在没有功能区的情况下使用伪装-似乎开箱即用的好行为是使用功能区-甚至@FeignClient注释的Javadoc 都说:
如果功能区可用,它将用于对后端请求进行负载均衡,并且可以使用
@RibbonClient与假客户端相同名称(即值)的来配置负载均衡器。
这表明即使两者服务于不同的目的,两者也具有密切的联系。
spring-cloud spring-cloud-feign netflix-ribbon spring-cloud-netflix
spring-cloud ×10
spring ×4
java ×3
spring-boot ×3
kubernetes ×2
apache-kafka ×1
consul ×1
docker ×1
jhipster ×1
netflix-zuul ×1
spring-kafka ×1