is it possible in JavaEE (JBoss AS5.1, EJB 3.0) to get notified when a jboss instance went offline? Specifically I want to receive a notification when a previously looked up ejb is not longer available or is available again (the ejb is not clustered, but that's another story).
My current workaround is to call a method called isAvailable which always returns true, when an exception occures I know the ejb is down. This online check obviously can't be the best way to do this.
If I understood it correctly, you are wanting to get alerted when a JBoss instance goes down. You would need an external monitoring and alerting tool such as RHQ or Hawkular to achieve this.
Having EJBs clustered would help providing high availability. However, you probably still want a motoring and alerting tool to monitor the cluster as well as other resources on the JBoss instances.
If you just care about when the EJB is unavailable and do not want to use an external tool, then you can create a Service MBean or a custom MBean. This way you can create a custom notification tied to your EJB lifecyle .
Please do keep in mind when you decide to upgrade to JBoss AS7 or Wildfly bits, this MBean will have to be changed since the MBean support is quite different in those versions.
Related
I know that by sending a http post request to http://host:port/shutdown, we can shutdown a Springboot application. Is it possible to restart the whole springboot application by sending a http request in a production environment? So we don't need to login in the server to do that. Thank you.
I don't think such a thing exists, I'll be glad to be proven otherwise:
Spring boot doesn't do any assumptions about the environment it runs in. So when spring boot process gets shut down, re-starting it again is "out of competence" of spring boot infrastructure which is just a bunch of java classes running inside a JVM process.
You can find Here a list of endpoints exposed by the spring boot. There is a "shutdown" method that you've mentioned there, but there is no "restart" functionality exposed.
Now there are other techniques that probably can help:
If the application gets shut down because of some illegal state of some spring bean, maybe it makes sense to expose some endpoint that will "clean up" the state and make application operational again. If the application has to be restarted due to changes in configuration files or something, then you might want to consider using spring cloud's Refresh Scope for Beans. It's kind of hard to provide more information here, because you haven't mentioned the reason for shutting down the application, but I guess you've got the direction.
Having said that, there are probably some different ways to achieve what you want depending on the environment your application runs in:
If you're running in AWS for example, you can take advantage of their autoscaling policies, shut down the application remotely and AWS will run another instance for you. I'm not an expert in AWS, but I saw this working in ECS for example.
If you're running "java -jar" just on some server and want to make sure that when your process ends (by using 'shutdown') it should be started again, its possible to use some kind of wrapper that would wrap the process in service and track the service availability. There are even ready solutions for this, like Tanuki wrapper (I'm not affiliated with this product but used once its free version and it served us great)
If you're using Docker infrastructure you can change the policy and restart the container automatically when it gets shut down, I haven't used this by myself, but according to This excellent blog post is perfectly doable.
You should look at Spring boot jenkins You will also find a small article explaining how to configure the project on jenkins.
I am creating a Java application in eclipse to let different devices communicate together using a publish/subscribe protocol.
I am using Jboss and ActiveMQ and I want to know if I should use an ActiveMQ resource adapter to integrate the broker in jboss in a standalone mode or I should just add dependencies in my pom.xml file and use explicit java code like indicated here http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html.
Here the documentation I found to integrate ActiveMQ within jboss in a standalone mode https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_A-MQ/6.1/html/Integrating_with_JBoss_Enterprise_Application_Platform/DeployRar-InstallRar.html
Could someone tell me what is the difference between the two approaches?
Here is the answer for my question:
The first approach starts a broker within your webapp itself. You can use a
normal consumer (not a message-driven bean - MDB), but only your webapp can
access it, via the VM transport (vm://).
The second approach lets the app server manage both the connection to the
broker and the creation of the broker, so it's probably also within the JVM
that runs your webapp and probably only accessible to your webapp, but
those details are hidden from you by the app server. You can only consume
messages via an MDB, but this provides a uniform interface that doesn't
need to change if you switch to another JMS provider in the future.
Since the standard way to integrate a JEE webapp with a JMS broker is via
the RA, I'd recommend using that approach simply for consistency and
standardization. That should also allow you to switch to a standalone
ActiveMQ broker (or another JMS product) in the future with minimal effort.
I have two Jboss instances installed on different servers. My aim is to manage a failover recovery between these Jboss instances. Load balancing is not needed. This is customer requirement. Normally client is connected to JBoss 1, perform a failover, and which the client will automatically connect to JBoss 2.
As I said I want to serve only one Jboss instance at a time.
Actually I have a solution, but I don't know if it works. My aim was to write a service that checks if Jboss is running. When I catch a failover, I want to change jndi.properties of client, then other Jboss instance will start to serve client request. But I do not know this solution works. Also Jboss can provide me a service( or other property) to check a specific instance is running?
Do you think my solution can work? Or How can I do this? Do I have to install Apache ? Apache provides failover without load balancing.
My company has plans to implement a clustered system with a lot of services that will be deployed automatically in different machines and will interconnect with each other (SOA style). Sometimes the services will have interdependencies.
For example:
Service B (application) can be started up only when the Service A (Database) is up and running.
Each service is planned to be run as a different java process, possibly deployed as a WAR (inside dedicated tomcat) or even without web at all.
For now we have all the services in the same WAR and only single tomcat that deploys the WAR.
All the services are defined via Spring and Spring manages dependencies for us.
So I'm asking myself whether exist some frameworks that will help to manage the services in a distributed environment as I've described above?
Thanks in advance
Use ZooKeeper.
Correction, use Netflix's Curator, a framework on top of zookeeper which simplifies the work with it.
Where I work I recently implemented a Coordinator class which has two methods:
waitForDependencies - a synchronic method that checks for the liveness of the current service's dependnecies and blocks the current thread until notified that all dependency services are alive. The liveness check is done by verifying the existence of nodes which are created by the depenedency services, at the end of their initializing process, by calling notifyUp
notifyUp - a synchronic method that notifies the world that the current service that calls that method is alive. The notification is done by creating an ephemeral (temporal, stays alive just as long as the connection in which it was created is alive) node in the zk cluster, which is looked for by other services which depend on it, using waitForDependencies
Netflix released their open source tool - Asgard that manages and deploys instances to a cloud. It is tightly coupled with EC2 (the last time I checked). Depending on whether you deploy to the amazon cloud you might find that useful. I'm unaware if it supports dependencies but it does manage deployments on a distributed environment. Netflix does talk about service dependencies a lot on their blog, so the deployment solution might have a feature to solve for that.
I'm not aware of any other service / framework that does this. If you were to write this on your own I guess you could configure a couple of Jenkins tasks that deploy services. One task can depend on another to simulate the service dependency. Pinging URL endpoints can check if Service A exists before B is deployed.
There's another way to look at this. You would not need to check for dependency if you ensure your services are all running properly. Monitoring tools like Nagios can help here. Troubleshooting faulty services immediately can help you focus on deploying Service A instead of checking your dependencies on each deployment.
I am starting a new enterprise project and use Glassfish 3 as an application server and NetBeans 6.9 as an IDE. I have some EJBs which I want to access remotely from a desktop Swing application. AFAIK there are two options - either use plain JNDI lookup or run the Swing application in an application-client container and use #EJB annotations. I tried successfully the first option but I had to copy all glassfish libraries to satisfy the dependencies(about 50MB, which I don't find normal). Now I try the second option. In NetBeans, I create a new Enterprise Application Client project, add the EJB project as a dependency and press run. I get the following exception: Sniffers with type [ejb] and type [appclient] should not claim the archive at the same time. Now if I remove the package checkbox, next to the EJB project in the Project properties of application client, I get a different ClassNotFound exception of my remote interface.
I feel kind of stuck:( Could some more experienced guys, tell me how do they access their EJBs remotely, using Glassfish 3? As I have written above, I succeed with the first option, but 50MB are too much in my opinion for a simple client.
Edit: What approach would you choose for deployment and remote access from the client, if you have the business logic in ejbs on a remote server?
Thanks for any suggestions you have!
Wish you all the best, Petar
I think the best approach in your case is to create a Servlet (or some other light simple component) in your server and make this guy talk to your EJB. If you choose this case, you will isolate your client/server comunication and your business logic implementation.