Giter Club home page Giter Club logo

Comments (4)

garyrussell avatar garyrussell commented on May 31, 2024

I can't understand what you are asking; please provide more context and the code you are having difficulty with.

The kafka sample clearly can get the toKafka message channel from the context, otherwise it wouldn't work.

from spring-integration-samples.

MayBing avatar MayBing commented on May 31, 2024

-------------Kafka Producer---------------------------------------
@configuration
public class KafkaProducerConfiguration {
@value("${kafka.topic}")
private String topic;

@Value("${kafka.messageKey}")
private String messageKey;

@Value("${kafka.broker.address}")
private String brokerAddress;

@Value("${kafka.zookeeper.connect}")
private String zookeeperConnect;

@Bean
@ServiceActivator(inputChannel = "inputToKafka",autoStartup="true")
public MessageHandler handler() throws Exception {
    KafkaProducerMessageHandler<String, String> handler = new KafkaProducerMessageHandler<String, String>(kafkaTemplate());
    handler.setTopicExpression(new LiteralExpression(this.topic));
    //handler.setMessageKeyExpression(new LiteralExpression(this.messageKey));
    return handler;
}

@Bean
public KafkaTemplate<String, String> kafkaTemplate() {
    return new KafkaTemplate<String, String>(producerFactory());
}

@Bean
public ProducerFactory<String, String> producerFactory() {
    Map<String, Object> props = new HashMap<String, Object>();
    props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, this.brokerAddress);
    props.put(ProducerConfig.RETRIES_CONFIG, 0);
    props.put(ProducerConfig.BATCH_SIZE_CONFIG, 16384);
    props.put(ProducerConfig.LINGER_MS_CONFIG, 1);
    props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, 33554432);
    props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
    props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
    return new DefaultKafkaProducerFactory<String, String>(props);
}

}
-------------Kafka Producer---------------------------------------

--------------fileter ----------------------------------------------
@webfilter(filterName = "activitiFilter", urlPatterns = { "/*" })
public class FilterConfiguration implements Filter {
private static final Logger logger = LoggerFactory.getLogger(FilterConfiguration.class);

private ApplicationContext applicationContext;

private MessageChannel messageChannel;

public void init(FilterConfig filterConfig) throws ServletException {
    ServletContext servletContext= filterConfig.getServletContext();

    applicationContext =WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    messageChannel = applicationContext.getBean("inputToKafka", MessageChannel.class);
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    chain.doFilter(request, response);
}

public void destroy() {
}

}
--------------fileter ----------------------------------------------

I run this,it well throw exception. Can not get inputToKafka.
Thank you very much!

from spring-integration-samples.

artembilan avatar artembilan commented on May 31, 2024

First of all GH issues are for problems and suggestions in the project.
Your issue looks more like a problem in your target application, not in any samples here.

The best place to raise similar questions is some community driver forum, like StackOVerfow. Right, exactly we may help you there, but that would be a fully different story.
Our mind won't be tied with the project context to determine an issue.

Another concern. Please, study how to comment on GitHub: https://help.github.com/articles/getting-started-with-writing-and-formatting-on-github/. It's enough complicated to read other posts without proper formatting.

And answering to your problem.

It seems for me like get access to ApplicationContext from Filter.init() is enough early.
On the other hand your architecture smells a bit. It's pretty strange to deal with messaging from so high protocol level.

There is also might be some issue that Filter accesses to the Serverlet's ApplicationContext, but that Kafka-specific config is raised with general ApplicationContext load. Etc., etc.

You really should provide more and more background to determine the issue...

Something like that.

Leaving as open until your feedback.

from spring-integration-samples.

MayBing avatar MayBing commented on May 31, 2024

thanks,I try it again.

from spring-integration-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.