小编Ind*_*nde的帖子

&nbsp jsx无法正常工作

我在jsx中使用 标记,但它没有渲染空间.以下是我的代码的一小段.请帮忙.

var Reporting=React.createClass({

  render: function(){
    return(
      <div style={divPositionReporting}>
          <p>Pricing Reports</p>
          <hr></hr>
          Select Scenario:&nbsp;&nbsp;
          <select>
            <option></option>
          </select>
          <button type="button">Get Pricing Report</button>
          <br/>
          Select Takeout Scenario:&nbsp;
          <select>
            <option></option>
          </select>
          <button type="button">Get Pricing Report</button>
          <br/>
      </div>
    );
  },

});
Run Code Online (Sandbox Code Playgroud)

html jsx reactjs

69
推荐指数
5
解决办法
6万
查看次数

Spring Kafka-使用Producer Listener配置KafkaTemplate与使用Listenable Future注册回调之间的区别

因此,我正在阅读Spring kafka文档,并遇到了Producer Listener。这就是Spring Kafka文档所说的-

“可选地,您可以配置带有ProducerListener的KafkaTemplate来获取发送(成功或失败)结果的异步回调,而不必等待Future完成。”

他们还指定了接口-

     public interface ProducerListener<K, V> {

      void onSuccess(String topic, Integer partition, K key, V value, 
      RecordMetadata recordMetadata);

      void onError(String topic, Integer partition, K key, V value, 
      Exception exception);

      boolean isInterestedInSuccess();

  }
Run Code Online (Sandbox Code Playgroud)

因此,我的理解是,如果您想对消息的成功和失败做一些事情,请实现ProducerListener接口,并将其注册到KafkaTemplate。它是异步的,因此您不必等待将来完成,就可以知道发送操作的结果。

在此下方大约3句话,它提到您还可以使用KakfaTemplate的send方法返回的ListenableFuture添加回调。这也是异步的。

 future.addCallback(new ListenableFutureCallback<SendResult<Integer, 
   String>>() {

 @Override
 public void onSuccess(SendResult<Integer, String> result) {
    ...
  }

  @Override
  public void onFailure(Throwable ex) {
    ...
  }

  });
Run Code Online (Sandbox Code Playgroud)

所以我想知道两者之间的确切区别是什么,因为它们都是异步的。是onSuccess和onFailure / onError方法中接收到的数据之间的区别。或者是在将回调函数添加到ListenableFuture之前(因为将来在不阻塞it-get()方法的情况下不知道异步计算的结果)之前,已经开发了在KafkaTemplate中添加ProducerListener的功能(反之亦然) 。因此,仅为了确保向后兼容,两者都可以继续使用。使用一种方法相对于其他方法是否具有任何性能优势。

先感谢您。

java spring spring-kafka

7
推荐指数
1
解决办法
2071
查看次数

无论选择哪个选项卡,每次都会调用所有React-bootstrap选项卡渲染函数

以下是我的代码:

var WholeTab=React.createClass                                                 
({                                                                             
  getInitialState:function()                                                   
  {                                                                            
    return {                                                                   
      key: 1                                                                   
    };                                                                         
  },                                                                           
  handleSelect:function(key)                                                   
  {                                                                            
    this.setState({key});                                                      
  },                                                                           
  render:function()                                                            
  {                                                                            
    return (                                                                   
      <Tabs defaultActiveKey={1} id="controlled-tab-example">                  
        <Tab eventKey={1} title="Tab 1"><One/></Tab>                           
        <Tab eventKey={2} title="Tab 2"><Two/></Tab>                           
        <Tab eventKey={3} title="Tab 3"><Three/></Tab>                         
      </Tabs>                                                                  
    );                                                                         
  }                                                                            
});                                                                            
var One=React.createClass({                                                    
  render:function(){                                                           
    alert("one");                                                              
    return(                                                                    
      <p>We are here</p>                                                       
    );                                                                         
  }                                                                            
});                                                                            
var Two=React.createClass({                                                    
  render:function(){                                                           
    alert("two");                                                              
    return(                                                                    
      <p>We are here</p>                                                       
    );                                                                         
  }                                                                            
});                                                                            
var Three=React.createClass({                                                  
  render:function(){                                                           
    alert("three");                                                            
    return(                                                                    
      <p>We are here</p>                                                       
    );                                                                         
  }                                                                            
});     
Run Code Online (Sandbox Code Playgroud)

我注意到的事情是,每当标签发生变化时,所有标签的渲染功能都会被调用,无论它们是否被选中,这种情况不会发生一次,而是发生3次.这只是一个蹩脚的例子,但如果我在每个标签中都有很多内容,我上面描述的行为肯定会影响网页的性能并使其变慢.我做错了什么或者这是react-bootstrap选项卡的错误,因为逻辑上不应该在每次更改时调用所有选项卡的render函数.

javascript tabs reactjs react-bootstrap

6
推荐指数
1
解决办法
834
查看次数

Spring.application.name在Bootstrap.properties中的意义

您好我有一个spring cloud配置服务器设置.我有多个配置文件(环境) - dev,prod,test等.

配置客户端上的bootstrap.properties的内容是 -

        spring.application.name=hazelcast,kafka.
        ....
        .... including uri of config server.
Run Code Online (Sandbox Code Playgroud)

现在在我的配置服务器指向的存储库中,除了特定于环境的application-dev.properties,application-prod.properties等之外还有application.properties.我还有hazelcast-dev.properties,hazelcast-prod.properties, kafka-dev.properties,kafka-prod.properties等

当我运行配置客户端spring boot应用程序时,profiles.active设置为dev.配置客户端能够从服务器检索以下文件 -

1.application.properties.

2.application-dev.properties.

3.hazelcast-dev.properties.

4.kafka-dev.properties.

当我使用prod配置文件激活时,将检索相应的prod文件(其中的值将添加到spring的环境中).

现在这很有效,但我想了解它背后的逻辑.spring.application.name是否特意适用于此?

http://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.0.0.M5/single/spring-cloud-config.html

我浏览了文档,事情并不是很清楚.

先感谢您!

编辑-

https://cloud.spring.io/spring-cloud-static/spring-cloud.html#_application_context_hierarchies

上面链接中的Section Bootstrap应用程序上下文几乎已回答了我的问题,但希望有人能够确认它.

java spring spring-cloud spring-cloud-config

5
推荐指数
1
解决办法
3604
查看次数

如何将Spring Boot中的application.properties文件外部化为外部依赖JAR?

我有一个简单的Maven模块(不是Spring Boot应用程序),我放置了我的application.properties文件.

我有6-7个Spring Boot应用程序,我不想application.properties在每个应用程序目录中都有一个文件.我更喜欢它,如果它在一个地方(外部Maven模块).

我将maven模块添加为每个Spring Boot应用程序poms中的依赖项.

但是,当我运行这些应用程序时,它无法自动检测application.properties文件,因为它来自物理上不存在于每个应用程序目录中的依赖jar.

有没有办法让这成为可能?我想避免在6-7个不同的位置拥有属性文件,因为这很难管理和处理.

先感谢您!

java spring spring-boot

4
推荐指数
1
解决办法
2736
查看次数

Spring Kafka-什么时候在幕后调用 Consumer.poll() ?

我有一个 Spring Boot 应用程序,其中有一个 Kafka Consumer。

我正在使用带有默认消费者配置的 DefaultKafkaConsumerFactory。我有一个并发设置为 1 的 ConcurrentListenerContainerFactory,我有一个用 @KafkaListener 注释的方法。

我正在听一个有 3 个分区的主题,我在不同的应用程序中部署了 3 个这样的消费者。因此,每个消费者都在监听一个分区。

假设在后台调用了对消费者的轮询并获取了 40 条记录。然后是每条记录,依次提供给用@KafkaListener 注释的方法,即提供记录1,等待方法完成处理,提供记录2,等待方法完成处理等等。是否发生上述情况,或者对于获得的每条记录,都会创建一个单独的线程并在单独的线程上进行方法调用,因此主线程不会阻塞并且可以更快地轮询记录。

我还想更清楚地了解消息侦听器容器是什么以及最终的消息侦听器。

先感谢您。

java apache-kafka spring-kafka

4
推荐指数
1
解决办法
3677
查看次数

Spring Kafka KafkaTemplate.flush() 需要吗?

我是第一次使用 Spring kafka,我使用 spring kafka 创建了生产者和消费者。我的 kafka 服务器在本地主机上运行,​​并创建了一个名为 test 的主题。我无法通过简单地调用向消费者发送消息

        KafkaTemplate.send(topicName,Data);
Run Code Online (Sandbox Code Playgroud)

在对同一个对象调用 send 之后,我不得不在 kafkaTemplate 上调用 flush() ,然后消费者才能接收数据。好的,它可以工作,而且很棒。但是有人可以向我解释幕后发生的事情吗?为什么需要调用flush方法。

来自官方 spring kafka 文档。

           public void flush()
Run Code Online (Sandbox Code Playgroud)

冲洗生产者。注意 如果 ProducerFactory 提供单例生产者(例如 DefaultKafkaProducerFactory),则调用此方法才有意义。

先感谢您。

java apache-kafka spring-kafka

3
推荐指数
1
解决办法
4425
查看次数

Spring Kafka-试图了解幕后的工作原理

考虑以下代码 -

@Bean
public ConsumerFactory<String, String> consumerFactory() {
    Map<String, Object> props = new HashMap<>();
    props.put(
      ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, 
      bootstrapAddress);
    props.put(
      ConsumerConfig.GROUP_ID_CONFIG, 
      groupId);
    props.put(
      ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, 
      StringDeserializer.class);
    props.put(
      ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, 
      StringDeserializer.class);
    return new DefaultKafkaConsumerFactory<>(props);
}

@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> 
  kafkaListenerContainerFactory() {

    ConcurrentKafkaListenerContainerFactory<String, String> factory
      = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}
Run Code Online (Sandbox Code Playgroud)

我创建了一个消费者工厂和一个concurrentKafkaListenercontainer Factory.我没有为监听器Factory设置并发性.我有一个用@KafkaListener注释的方法

@KafkaListener(topics = "topicName")
public void listen(String message) {
    System.out.println("Received Message: " + message);
Run Code Online (Sandbox Code Playgroud)

当我不设置并发属性时,Spring会创建1个消费者实例,1个kafka监听器容器属于消费者工厂中指定的组吗?

如果我将并发性更改为3,那么Spring会创建3个消费者实例,因此在配置消费者工厂和3个侦听器容器时,同一个消费者组中有3个消费者吗?

此外,根据并发性,我们假设我们现在只听一个主题,我们将有3个用@kafkalistener注释的方法,如果没有指定分区,则所有3个方法都会监听不同的分区(由kafka以循环方式提供).?

我是卡夫卡的新手,想澄清我的理解.

java spring spring-kafka

1
推荐指数
1
解决办法
992
查看次数

Spring Cloud Config-属性解密在客户端不起作用

我有一个用于配置客户端和配置服务器的基本设置(与此处的教程完全相同-https : //spring.io/guides/gs/centralized-configuration/

我的问题是我可以解密服务器端的属性并将其作为纯文本发送,但是不能解密客户端而不是服务器端的属性。我正在使用对称加密,并且已经多次阅读了文档,但是无法在客户端工作时得到解密。

我在服务器端添加了以下属性,因此它不会在服务器端解密属性-

       spring.cloud.config.server.encrypt.enabled=false
Run Code Online (Sandbox Code Playgroud)

我有一个application.yml文件,该文件具有加密的值-

       name: '{cipher}hdshdghsgdhjsgdhsgdyassudyadssd2313wdw2e'
Run Code Online (Sandbox Code Playgroud)

我尝试将ENCRYPT_KEY / encrypt.key添加为客户端系统属性的环境变量。另外,尝试在application.properties和bootstrap.properties中添加相同的内容,但客户端无法解密。

先感谢您。

配置客户端POM-

.......................

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>

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

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

  <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>

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


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


<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</dependency>

    <dependency>
    <groupId>com.auth0</groupId>
    <artifactId>java-jwt</artifactId>
    <version>3.3.0</version>
    </dependency>


    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka-server</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Edgware.SR2</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

..............

在配置服务器中,我添加了属性-

           spring.cloud.config.server.encrypt.enabled=false
Run Code Online (Sandbox Code Playgroud)

在配置客户端上,我在application.properties和bootstrap.properties中都添加了crypto.key。 …

java spring-boot spring-cloud spring-cloud-config

1
推荐指数
1
解决办法
1607
查看次数

Spring Cloud Zuul - 自定义错误过滤器

我想添加一个自定义错误Zuul过滤器,并希望确保SendErrorFilter不执行.我看了几个github链接,包括Spring-cloud/spring-cloud-netflix和各种堆栈溢出问题: -

自定义Zuul异常

覆盖Zuul Filter SendErrorFilter

我的代码如下 -

  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 spring-cloud netflix-zuul spring-cloud-netflix

0
推荐指数
1
解决办法
3212
查看次数