I need to poll a folder for changes i.e. files added, modified and deleted.
If I want to distinguish between the different types of events listed above would I need to implement a custom poller i.e. implement AbstractPoller. I have already implemented a poller that does this for a different project but would like to us spring integration and batch as I need to use other functionality.
What is the best way of doing this?
Thanks
Wouldn't you mind to share your code? BTW you always can utilize the custom code with <int:inbound-channel-adapter> as a ref and method, where an underlying POJO will return some object which will become as payload of message.
As you know the <int:inbound-channel-adapter> should be configured with <poller> how often you want to call that undelying POJO.
Related
The existing code I’m working with is creating a new method with duplicate code each time because it is using #ManagedListener configured for the different Kafka Topics and diff configurations using Java Spring Boot.
`#ManagedListener({configurations for Kafka topic-a})
method1(){
//logic to handle data
}
#ManagedListener({configurations for Kafka topic-b})
method2(){
//same logic as method1 copied
}
#ManagedListener({configurations for Kafka topic-c})
method3(){
//same logic as method1 copied again
}`
Is there a way I can have a listener configured to different Kafka topics configurations that all call method1 directly? I’m trying to find a way to avoid duplicate code.
I tried to add multiple #managedListener annotations to the same method, but it seems like it has to be one to one. It will work if I duplicate the code, but it seems counterintuitive
The expected result is to be able to receive messages from multiple different Kafka topics.
I'm not sure about #ManagedListener usage here since #KafkaListener is what's more commonly used to setup a Kafka consumer. This annotation already supports consuming multiple topics on its own (assuming same consumer config factory), so you wouldn't need multiple methods anyway.
But the annotations don't prevent you from calling any common methods.
I'd suggest extracting all common logic to a function that is not annotated as a Kafka listener, however.
I don't know what #ManagedListener is, but #KafkaListener is a #Repeatable annotation (you can put multiple annotations on a method).
I need to make a REST API so two components can communicate with each other.
The flow starts like this:
Component 1 sends a request
The API processes it and, if everything's correct, writes inside Component 2 DB
Various data processing...
Component 2 sends a request
The API processes it and, if everything's correct, writes inside Component 1 DB
How do I make this appen in Spring Boot? I don't need any domain class, so I don't think I need to use JPA.
Update: I need to make it work with JdbcTemplate
Thanks in advance
I'm not sure what you intend to achieve here but this is what I would suggest you do if you really need to achieve this with JDBC template.
In your configuration file: e.g application.properties, you could specify keys to hold values used in configuring every different connection to the databases you need to interact with. A naive example could be:
app.datasource1.url=...
app.datasource1.driver=...
app.datasource1.username=...
app.datasource1.password=...
app.datasource2.url=...
app.datasource2.driver=...
app.datasource2.username=...
app.datasource2.password=...
You could create beans of these connections in a config class and differentiate them with names (qualifiers), one of them could be a tagged primary data source and the other a secondary data source. As an alternative, however, you can do 3 each time you need an instance of the DB connection.
Since you are using the JDBC template, in the service classes or implementations where you make calls to the database, you could start first by creating a connection (an instance of JDBC Template) before using it.
With this approach, you can create as many connections as you want to as many DB as you want. Don't know if this helps.
I have a class which has many simple attributes (type is int,String,...). It also has an attribute which is an instance of another class of mine. Now I want to send the object via a Redis pub/sub channel. To do this I serialize it with the GenericJackson2JsonRedisSerializer. As both classes have their own repository I don't want to embed the object every time but instead only send the ID. I thought that this should be possible by adding the org.springframework.data.annotation.Reference annotation to the field.
Unfortunately this didn't work, instead it just embeds the object. Is there anything I did wrong? What do I have to do to just get the object's ID in the serialized version?
Thank you for your help!
Alright after way too much research for such a basic thing I finally figured out how to do it.
Basically I needed to add the com.fasterxml.jackson.annotation.JsonIdentityInfo annotation to the class or field. As already stated in the question this produced the same result, first time completely included, afterwards only referenced.
No documentation mentioned how to always have the id, I had to look into the code: there's another annotation com.fasterxml.jackson.annotation.JsonIdentityReference which has a boolean property called alwaysAsId. If you set this one to true it always adds the id instead of the object.
To get the deserializing working one needs to specify a custom resolver for the ids. As I'm using Spring it has been quite easy to get access to my repository.
Did you use Spring Data Redis ? http://projects.spring.io/spring-data-redis/
Check http://docs.spring.io/spring-data/redis/docs/current/reference/html/#redis.repositories.references
If you are not using Spring Data Redis I think you should have to implement your own reference when serialize/deserialize your data.
You can implements your own Serializer with
YourObjectSerializer extends Jackson2JsonRedisSerializer
Is there a way for me to do this and is it appropriate? I need the data that comes back from an endpoint in a different controller. Would I create a HTTP request on right in the java code?
Please advise if this is an appropriate question for here...
You might want to consider separating the retrieval of the data and the presentation of the data from your current endpoint in two different classes. After you've done that you can easily have two Spring controllers share the same source of data. One of them is your current Spring controller, the other one is the new one.
Performing an HTTP request from one Spring controller to another one in the same application would introduce a lot of overhead and complexity. I would try to avoid that.
The correct thing to do is to call the service that is generating the data for the controller in the controller that needs the data.
I hope that you've structured your project as an MVC. If not, you should be addressing that before you do anything else.
I am new to playframework, so although this might be a newbie question, I need to ask. I have an application, where the database data can be changed by web requests, as well as by incoming emails.
I know that controllers are primarily used for web requests. Therefore, should I encapsulate the model modification logic in a separate class, which I should call from both the controller, and the guy who accepts the emails. Is this what the Service paradigm is used for?
Second, what should I use for the mail acceptor. A job or a plugin? Currently I created a job which refreshes itself every 10 seconds, but didn't know if it is appropriate to use a job to modify the DB. Perhaps, the job can trigger an internal event which a plugin will listen for ...
Yes you can update the model throught a job, job are transactionals.
For your common logic, if it relates to a specific model object, you can use a method on this object to put your common logic : put in static methods every code that is not tied to a specific instance and in non static methods logic that is tied to a specific instance.