0

We are trying to access consul KV store with the below set up in bootstrap and reading it with @Value("${configvalue}") in the code.

  application:
        name: appname
   cloud:
   consul:
      host: consulhost
      port: 8500
      config :
       enabled: true
 


@Value("${configvalue}") 
private String configvalue; 

@GetMapping("/home") 
private String home() { return configvalue; } 

public Message<String> trans4mformat(Message<JsonNode> msg) 
{ 
System.out.println("********Got the consul parameters-->"+configvalue);
 //do transform and return Message<String> 
} 

<int:gateway  id="inboundListener" service-interface="KafkaGateway" default-request-channel="inboundChannel" error-channel="errorChannel"/>

<int:transformer id="transform" input-channel="inboundChannel" output-channel="outboundChannel"  method="trans4mformat" requires-reply="false" > 
<bean id="trns4m" class="com.package.Tranformation"/>
<int:poller fixed-rate="5"/>
</int:transformer>

This works well when used inside a Rest Controller; But we have a kafka listener and an integration flow starting from it and we need to access this @Value("${configvalue}") inside transformer ? This always gives null; though we can see the value with the get HTTP call in a separate method.

  • Hey, Can you post what you have tried so far? – Christlin Panneer Jul 15 '20 at 17:30
  • What is this `@Value("key")` referring to? How would you do that if there was no such a `@Value` annotation? – Artem Bilan Jul 15 '20 at 17:31
  • Tried adding a property for the transformer and injecting from config. Also tried using com.ecwid.consul client – Sajeevan mp Jul 15 '20 at 17:33
  • @ArtemBilan .. We know the value is present as we are able to see it via another url with a RestController. – Sajeevan mp Jul 15 '20 at 17:35
  • That's wasn't my question though... What is that `key` and how to get access to it without a `@Value` annotation? Show what works and what doesn't. Editing your question though. Don't comment here with a code: it is just not readable. – Artem Bilan Jul 15 '20 at 17:37
  • @ArtemBilan As per this link https://stackoverflow.com/questions/36629943/consul-first-bootstrap-with-spring-cloud-config I was able to to get the value of the key created in consul with @Value("${key}"); but not inside a spring Integration transformer. Make sense? – Sajeevan mp Jul 15 '20 at 17:51
  • No. Show your working code and what you have with Spring Integration so far. – Artem Bilan Jul 15 '20 at 17:55
  • @Value("${configvalue}") private String configvalue; @GetMapping("/home") private String home() { return configvalue; } public Message trans4mformat(Message msg) { System.out.println("********Got the consul parameters-->"+configvalue); //do transform and return Message } I am calling this trans4mformat from IntegrationContext immediately after a kafka Listner and I see the message but not the configvalue; which Ideally should be present @ startup itself; thats why I see that value when I do a get HTTP Request. – Sajeevan mp Jul 15 '20 at 18:05
  • Well, I asked to not show a too much code in the comment... Please, edit your question with working code and what you try to achieve. With an appropriate formatting. We can't help you if we don't speak the same language. – Artem Bilan Jul 15 '20 at 18:28
  • @ArtemBilan sorry I am totally new here.[both stackoverflow and spring integration] Edited the question now. – Sajeevan mp Jul 15 '20 at 18:49

1 Answers1

0
AbstractApplicationContext context = new ClassPathXmlApplicationContext("/IntegrationContext.xml",Application.class);
KafkaGateway kgw = (KafkaGateway) context.getBean("inboundListener");

This is what I was doing; now I changed this to

    @Autowired
    private KafkaGateway kgw;

Now I dont see that Issue any more. Thanks