java

How to invoke broadcast EJB at all JBoss cluster members

According to a title, if have to invoke all ejb beans of a given type at once on all cluster members, below is a quiet simple way how to do it.

1. Import into your project required modules/dependencies

Maven dependencies

Runtime JBoss modules depencies

Defined  jboss-deployment-strucutre.xml file:

Dependencies might be alternatively defined in MANIFEST.MF as entry:

2.  Implement service that will invoke method on all cluster members

 Important notes on implementation:

  • JmsAdapter is an @Stateless EJB
  • Broadcast method is invoked synchronously on all cluster members, but there is an async equivalent : callAsynchMethodOnCluster
  • Implementation of broadcast requires private JBoss modules which are not supported by Red Hat

 

Managing HornetQ queues via JMS API

HornetQ offers a lot of resource management operations, but unfortunately it is not well covered by documentation ;(
In following tutorial I will try to show you how to manage HornetQ queue via JMS API.

1. Add hornetQ dependencies:

  • As library is available at JBoss AS, I personally prefer to add dependency at scope provided and include module dependency in MANIFEST.MF file
  • In case of debugging, consider adding also artifacts hornetq-server, hornetq-jms-server
2. Add class that will handle invocation of management operations:

3. Invoke adapter from previous point:

  • pay attention at queue address, because jms queues  should starts with prefix jms.queue.*
  • in case of operations parameters, add them as varargs

In the next post I have explained how to find out which management operations are available.

 

How to add custom logging handler in JBoss 7 via CLI

Yesterday I was facing problem of adding in JBoss  6.2 EAP custom-handler in loggging submodule via command line interface, all because of not documented syntax of creation of properties part.

All I wanted to add was:

And finally the solution is:

 

How to run JRockit Mission Controll with JBoss 7

Due to [AS7-1859] issue it is not possible to connect to JBoss7 via java agent. But fortunately there is other way.

1. Start JRMC:

Start JRMC as you usually do, but this time add following parameters:

where {JBOSS_HOME} points to JBoss 7 home directory, and {JROCKIT_HOME} points to JRockit JDK instalation folder. Also double check if libraries are present, as they vary from JB version (those above are valid for JBoss 7.1.1)

2. Create new JRockit connector:

In JRMC go to “connectors -> add connection”, and use following properties:

  • Host JDK version: Custom JMX service URL 
  • JMX service URL: service:jmx:remoting-jmx://{JBOSS_SERVER_HOST}:{JBOSS_MANAGEMENT_NATIVE_PORT} 

 

References:

How to inject mock into CDI context with Arquillian behind the scenes

 

My goal was to mock database, so every component in CDI based application would use mock instead of original implementation. I also had to have possibility to control my mock in JUnit test runtime. I struggle with this problem almost whole day and finally found satisfying solution :)

Not all steps are necessary, but I strongly encourage You to follow all of them.

1. Create stereotype for your mocked objects

2. Register newly created stereotype

3. Create mock factory

4. Write unit test

 

How to deploy arquillian EAR package to remote server with all required dependencies

If you want to test your enterprise package with arquillian, here is my way how to do it:

0. Prerequisites

  1. Maven multimodule project
  2. application server (I’ve used Weblogic 12c)

1. Add required maven dependencies to projects:

 

 2. Create base test class

Note that all required dependencies and test classes are included in the package, so  NoClassDefFoundException will not bother you anymore ;)

3. Add arquillian.xml descriptor to src/test/resources

  3. Write a test