Problem with rabbitmq-client (Java) when used in OSGI-bundle (felix)

231 views
Skip to first unread message

Thomas Jaspers

unread,
Nov 29, 2017, 3:00:29 AM11/29/17
to rabbitmq-users
When using the latest version 5.0.0 of the rabbitmq client.jar sending a message is resulting in the following NPE:

java.lang.ExceptionInInitializerError
    at com.rabbitmq.client.impl.AMQConnection.defaultClientProperties(AMQConnection.java:75)
    at com.rabbitmq.client.ConnectionFactory.<init>(ConnectionFactory.java:100)
    at 
<skipped>
Caused by: java.lang.NullPointerException
    at java.util.Properties$LineReader.readLine(Properties.java:434)
    at java.util.Properties.load0(Properties.java:353)
    at java.util.Properties.load(Properties.java:341)
    at com.rabbitmq.client.impl.ClientVersion.<clinit>(ClientVersion.java:35)
    ... 89 more

The code used for sending is taken from the most simple example and looks as follows:

ConnectionFactory factory = new ConnectionFactory();
factory
.setHost("localhost");

try {
 
Connection connection = factory.newConnection();
 
Channel channel = connection.createChannel();

 channel
.queueDeclare(QUEUE_NAME, false, false, false, null);
 
String message = "Hello World!";
 channel
.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
 channel
.close();
 connection
.close();
} catch (Exception e) {
 LOG
.error("Error publishing event", e);
}



The reason for this exception was traced down to the following lines of code in the ClientVersion-class.

public class ClientVersion {
 
private static final Properties version = new Properties();
 
public static final String VERSION;

 
public ClientVersion() {
 
}

 
static {
 
InputStream inputStream = ClientVersion.class.getClassLoader().getResourceAsStream("version.properties");

 
try {
 version
.load(inputStream);
 
} catch (IOException var10) {
 
;
 
} finally {
 
try {
 
if(inputStream != null) {
 inputStream
.close();
 
}
 
} catch (IOException var9) {
 
;
 
}

 
}

 VERSION
= version.getProperty("com.rabbitmq.client.version", ClientVersion.class.getPackage().getImplementationVersion());
 
}
}


This statement resolves to NULL: InputStream inputStream = ClientVersion.class.getClassLoader().getResourceAsStream("version.properties");

The reason is that the wrong class loader is used (the bundle class loader) as this is running in an OSGI-bundle and thus the version.properties file cannot be found.

We kind of "solved" this problem by switching to an earlier version (3.5.1) of the rabbitmq client, but this is for sure more a workaround than a real solution ;-).

Question now is: Is there a solution to still make use of the latest version in an OSGI context? 

Thanks in advance
- Thomas  

Arnaud Cogoluègnes

unread,
Nov 29, 2017, 4:47:15 AM11/29/17
to rabbitm...@googlegroups.com
Can you provide steps to reproduce?

Have you tried newer versions than 3.5.1? I'm pretty sure some people are using 3.6.x or even 4.x on OSGi, but maybe on other OSGi frameworks than Felix.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Jaspers

unread,
Nov 29, 2017, 5:23:58 AM11/29/17
to rabbitmq-users
The problem occurs with the newer versions, the older versions are not trying to read version.properties from class path and are therefore working.
Steps to reproduce might be complicated as it requires setting up felix, etc. ... 
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.

Arnaud Cogoluègnes

unread,
Nov 29, 2017, 8:33:00 AM11/29/17
to rabbitm...@googlegroups.com
I filled in an issue: https://github.com/rabbitmq/rabbitmq-java-client/issues/334

Please follow up on this thread to test when I push a SNAPSHOT with the suggested alternative.

To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

Arnaud Cogoluègnes

unread,
Nov 29, 2017, 9:45:24 AM11/29/17
to rabbitm...@googlegroups.com

Thomas Jaspers

unread,
Dec 1, 2017, 4:15:12 AM12/1/17
to rabbitmq-users
Oh, cool, I will do on Monday, thanks!


Am Mittwoch, 29. November 2017 15:45:24 UTC+1 schrieb Arnaud Cogoluègnes:
On Wed, Nov 29, 2017 at 2:32 PM, Arnaud Cogoluègnes <acogol...@pivotal.io> wrote:
I filled in an issue: https://github.com/rabbitmq/rabbitmq-java-client/issues/334

Please follow up on this thread to test when I push a SNAPSHOT with the suggested alternative.

Arnaud Cogoluègnes

unread,
Dec 5, 2017, 10:45:37 AM12/5/17
to rabbitm...@googlegroups.com
Did you manage to test the snapshots?

To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages