Check if Queue Exists or Not

327 views
Skip to first unread message

dla...@gmail.com

unread,
Jun 14, 2017, 8:45:02 AM6/14/17
to Hazelcast
Good day,

I was wondering if the hazelcastInstance.getQueue("my-distributed-queue") will ever return null?

If an application is configured to use a certain Queue but there is a config error it seems a Queue is just created using some default configuration.

If there any way to avoid this and return something like null or throw and exception if a Queue for the supplied name does not exists?


Fuad Malikov

unread,
Jun 14, 2017, 2:39:44 PM6/14/17
to Hazelcast
Hi, 

You can either use 
hazelcastInstance.getDistributedObjects();
and see if the Queue object is there or you can use Client Security and Permissions by not giving this client a right to create a Queue. http://docs.hazelcast.org/docs/latest/manual/html-single/index.html#permissions. Note that the latter is an Enterprise Feature. 

Best, 

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+unsubscribe@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at https://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/351b888e-6c76-4c78-be3e-990733a95f5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dla...@gmail.com

unread,
Jun 19, 2017, 4:33:17 AM6/19/17
to Hazelcast
Hi,

Problem I get here is that hazelcastInstance.getDistributedObjects(); is empty if no one has ever caused the queue to be created.

So if the queue was never configured properly it will be created using some default config this becomes hard to debug/fault find as asking for a queue configuration with the required name also gives one a default instance of the configuration.


On Wednesday, June 14, 2017 at 8:39:44 PM UTC+2, Fuad Malikov wrote:
Hi, 

You can either use 
hazelcastInstance.getDistributedObjects();
and see if the Queue object is there or you can use Client Security and Permissions by not giving this client a right to create a Queue. http://docs.hazelcast.org/docs/latest/manual/html-single/index.html#permissions. Note that the latter is an Enterprise Feature. 

Best, 
On Wed, Jun 14, 2017 at 5:40 AM, <dla...@gmail.com> wrote:
Good day,

I was wondering if the hazelcastInstance.getQueue("my-distributed-queue") will ever return null?

If an application is configured to use a certain Queue but there is a config error it seems a Queue is just created using some default configuration.

If there any way to avoid this and return something like null or throw and exception if a Queue for the supplied name does not exists?


--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.

Ahmet Mircik

unread,
Jun 19, 2017, 6:14:19 AM6/19/17
to Hazelcast

Hi,

You can define your own config-pattern-matcher and throw exception when nothing is found for the name. Default config-pattern-matcher returns null, if there is no config found and in that case hazelcast returns a queue with default config.

Here is an example config matcher implementation (MatchingPointConfigPatternMatcher is the default impl used internally )

private static class TestConfigMatcher extends MatchingPointConfigPatternMatcher { 

@Override public String matches(Iterable<String> configPatterns, String itemName) throws ConfigurationException {
 String matches = super.matches(configPatterns, itemName);
 if (matches == null) { 
       throw new ConfigurationException("No config found for " + itemName); 
 }
  return matches; 
} 
}

You need to set above config matcher to hazelcast config object (either client or server config) before use:

Config config = new Config();
config.setConfigPatternMatcher(new TestConfigMatcher());

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

To post to this group, send email to haze...@googlegroups.com.
Visit this group at https://groups.google.com/group/hazelcast.

dla...@gmail.com

unread,
Jun 29, 2017, 3:38:29 AM6/29/17
to Hazelcast
Thanks will try this.

I found another alternate work around that can also be implemented!

Basically it goes like this:

if (hazelcastInstance.getConfig().findQueueConfig("some-queue-name").getName().equalsIgnoreCase("default"))
{
   // The Queue is NOT configured and the default configuration IS being used
}
else
{
  // The Queue is IS configured and the default configuration is NOT being used
}

Please note that hazelcastInstance.getConfig().getQueueConfig("some-queue-name") returns a QueueConfig with the name set to "some-queue-name" using the default configuration so use findQueueConfig()

Hope this helps someone else out there!

But thanks for everyone's inputs!
Reply all
Reply to author
Forward
0 new messages