How to connect Kafka to legacy Spring - java

I am working on PoC of connecting legacy Spring application to Kafka. It is war application to be deployed in Tomcat, Spring version 4.3.12. Is there some library to make communication with Kafka almost as easy as with Spring Boot? I need just fundamental operations: sending message, listening for confirmation, receiving.
I have some experience with Spring Boot support as is provided in org.springframework.kafka:spring-kafka library. I am not sure how to efficiently adopt Kafka for legacy Spring - I'm thinking of using Kafka Java client which looks promising but as I am used to working at Spring Boot abstraction level I don't have clue how much code should I supply myself.
Web search is not much helpful in this case since it tends to show Spring Boot-related solutions. Migration of legacy application is considered too, I just need to have some idea how difficult each way is.

kafka-clients is all you need (from Maven Central, not Confluent). You could go a step further and look into Log4j2 Kafka bridge, then property files for that.
If you want to externalize config into regular Java .properties file, you can, or you can pull values from environment variables, if you follow 12-factor principles.
But if you don't already have Spring Boot dependencies, then I do not think adding them is worth it for only Kafka.
Also, the Spring-Kafka documentation covers how to configure your app without Boot.

Related

Why is Spring Cloud called "Cloud"?

Spring Cloud is a framework that helps implementing a Microservices architecture (with common patterns and practices, like Runtime Configuration, Tracing, Circuit Breaker, Service Discovery, and so on), but it has nothing to do with "Cloud", right?
Microservices and Cloud are a good match when combined, but Spring Cloud helps with microservices, not with cloud. Am I right?
My question is: wouldn't Spring Microservices be a better name for Spring Cloud?
I don't want to change its name, I just want to be sure that I understand the framework correctly.
For the record, "Spring Cloud Netflix" or "Spring Cloud Amazon" would be well named, because they do help with the integration of those specific Cloud platforms.
Well, probably people from Pivotal responsible for naming can give you the good answer, I can only speculate.
In my understanding, Spring Cloud is set of tools that allow (mainly spring boot driven) application to be written in "Cloud Native" way. When you run in the cloud, it makes sense to protect the application with Circuit breaker, to use service discovery in a way that scaling out the various parts of the system will work seamlessly, and so on and forth.
Now, spring boot application don't necessarily run in the cloud, in fact its possible to run spring boot app on your "personal" (on-premise) server.
Spring boot applications are not restricted to run microservices as well, its possible to run monoliths with spring boot as well. In fact there are many monolith application that use spring under the hood.
Now, can you take tools from spring cloud and use them for applications not running in the cloud? Yes of course you can. Can you benefit from these tools? Probably yes, but not so much if you run one microservice on one on-premise server (I'm exaggerating but still).
Probably (again a speculation) it will be correct to say that the more your environment "resembles" the cloud (public cloud, private or hybrid) - the more benefits you'll see from using these tools. Hence the name :)
The Spring Cloud library is a general-purpose tool for the implementation of distributed systems.
Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state)
The microservice architecture is not necessarily built on cloud technologies, such as Amazon and might be run on the self-hosted servers.
Moreover, it's true that the microservice architecture is based on the "architectural patterns" such as service discovery, API gateway, sidecar-proxies etc., however it doesn't mean that it is the only architecture that can benefit from these characteristics.
I believe the name Spring Cloud was chosen well since it is focused on the implementation of distributed systems.

Accepting request from specific ip in Spring Boot

I referred this tutorial to restrict certain ip in jboss and Spring Boot application.
http://www.mastertheboss.com/jboss-web/jbosswebserver/how-to-restrict-access-to-jboss-web-application-by-ip-or-host
But the tutorial is not complete. Where should I place those codes? Are there any other methods to do that?
If any one know any other methods please mention that here. Thanks in advance.
IMO the Valves mentioned in tutorial are the ways to customize tomcat embedded into the Jboss application. Note that this tutorial is really old - from 2014, probably JBoss has changed since then.
I remember back that times JBoss indeed included Tomcat inside to handle the web requests, so probably there was some kind of server.xml of tomcat.
Now, there are other ways:
Place the application behind some proxy that would restrict the access. Probably its the best approach if your environment supports that.
Use filters inside the application. You can create a web filter and register it in spring boot application regardless whether its a Jar with embedded server or WAR that you're planning to deploy on JBoss. This can be really flexible but on the other hand it includes some java coding and will consume some resources of your application. You can use this approach if you don't have spring security in your application and you don't want to introduce one, otherwise read (3).
Kind of paraphrase on 2 but used with spring security, that has the filtering facility built in: here is how you can do that. Note that besides the actual Java code used for implementation, 3 and 2 are pretty similar.
I'd approach this problem in the following way:
If the IP where connections are accepted is subject to change, I'd configure reverse proxy like nginx. This would mean you don't have to redeploy or restart your application if the IP address changes. Please see this guide for details on how to configure nginx: https://docs.nginx.com/nginx/admin-guide/security-controls/controlling-access-proxied-tcp/
Otherwise I'd refer to this article: https://access.redhat.com/solutions/18412 describing the following configuration in WEB-INF/jboss-web.xml:
<valve>
<class-name>org.apache.catalina.valves.RemoteAddrValve</class-name>
<param>
<param-name>allow</param-name>
<param-value>127.0.0.1,127.0.0.2</param-value>
</param>
</valve>
</jboss-web>
To me this concern should be handled on infrastructure level, not in application container. I would suggest to look into AWS Security Groups or equivalent concepts in other cloud providers.
If you are running it in private cloud/bare metal, you should investigate to restrict it on transport layer your infrastructure provides. There should be some possibility to configure firewall rules.

How to use Spring Boot Activity Rest api in Activity App Ui

I am new to Activity process. I want to used the Activity with spring boot application. So, I want to used the rest api in spring boot and that rest api will be used by activiti-admin.war and activiti-app.war.
So, when I have deployed process from spring boot that will be available in UI and add some Listener while assigning task will be called in my spring boot app.
Can any one help.
Thanks in advance.
It sounds like you are using the version 6 Activiti build.
Both the activiti-app and admin-app already use "a" REST API to communicate to the backend, however it is not the community REST API that will be deployed with your Spring boot application (I assume you are using the Activiti spring boot starter rest).
It is not actually going to be trivial to separate the activiti-app and admin-app UI from the service layer as they are quite tightly coupled, but it is certainly possible.
While I haven't actually attempted it, it may be easiest to take the activiti-app build module (activiti-ui/activiti-app) and separate the client and server portions since the client is now a regular AngularJS application.
Is this what you are looking for?
Thanks,
Greg
I hope you are looking for something like this. It seems they are planning to support activiti app with your own spring boot application in Activiti 7.
If you are able to solve the case, please help with the sample structure. I am bit stuck with same usecase.

How to run multiple Spring Boot applications easily on Production

I am trying to figure out an easy way to manage many Spring Boot applications on my Production server. Right now I have many fat jars running on different folders where each one has its your own script to start/stop the application and there's an external folder for the configurations (logback, properties, xml). For record those configurations are loaded by command line -Dloader.path to Spring Boot execution.
So how can I avoid conflicts for the same http/https port already running on Production? Does exist any kind of application manager where system administrators could control it? One solution I found was to virtualize Spring Boot applications with Docker, but my environment is Unix Solaris.
Is there any java solution for this scenario?
You can have a look at Spring Cloud which will give you better control and management when running multiple boot applications. All components of Spring Cloud
might not be useful to you, but few of them will help in port resolution, service rerouting and property maintenance. Along with the above you can also try SBA.
Along with the above you can also try Nginx for UI load balancing and reverse proxy.

What do I need to download to start developing apps using the Spring framework?

I need to start developing applications using the Spring framework, and am wondering what tools I need to download to have me up and running.
On the SpringSource website I am seeing all these applications to download and I am wondering, do I really need all this? And what versions should I use, especially for Spring Framework?
Spring Framework
SpringSource dm Server Samples
Spring Security
Spring Web Flow
Spring Web Services
Spring Dynamic Modules
Spring Integration
Spring Batch
Spring.NET
Spring JavaConfig
Spring LDAP
Spring Extensions
Spring IDE
Spring BlazeDS Integration
SpringSource Bundlor
Spring ROO
What other applications do I need to download (eg. Struts, Glassfish, Apache, etc.)?
This depends on what you want to use Spring for. Typically that's Web applications. If so you only need two things:
Spring framework (with minimal dependencies); and
A servlet container (eg Tomcat) or a full-blown application server (eg Glassfish, JBoss).
Everything else is optional. I believe the only required dependency is Apache Commons logging. Depending on what features you use, you may well need more.
If so, here is a [tutorial][1] that creates a barebones Spring MVC project. There are countless others around for that and other topics.
It's entirely possible to use Spring in, say, a Swing application in which case you obviously don't need a servlet container.
All you need from SpringSource is the Spring Framework.
Spring 3.0 is on the way, but for now, use 2.5.6.SEC01, the current production release.
You can get started with a simple servlet container (ie: Tomcat) rather than a full blown application server (eg: JBoss, Glassfish).
The Spring Framework comes bundled with jars for web development - ie: spring-web and spring-webmvc.
See #117535 for a simple example of using Spring MVC.
It mainly dependent on what you need Spring for. Each and every piece of Spring can, actually, be used in separation from the rest. You may use it only for IOC, in this case you don't need, for example, MVC and Servlets, etc...
The easiest way to start is to dowload the main package from http://www.springsource.com/download/community?project=Spring%20Framework
You can use Spring from any IDE
The best way is to use Maven with your project. Basically all you have to do is edit your pom.xml file and tell it that you want to use Spring. Then when you compile your code, Maven will go out and automatically download the Spring libraries you need from their public repository.
Here's an example:
http://pookey.co.uk/blog/archives/63-Getting-started-with-Maven-and-Spring.html

Categories