Question

We are using an embedded Glassfish Server in our testing environment. We use the org.glassfish.embeddable.CommandRunner interface to execute administrative tasks (i.e., what we do with asadmin with a standard standalone Glassfish server)

Example:

GlassFish glassfish = GlassFishRuntime.bootstrap( bp ).newGlassFish( gfp );
CommandRunner commandRunner = glassfish.getService( CommandRunner.class );
commandRunner.run(
  "create-jms-resource",
  "--restype",
  "javax.jms.Queue",
  "SOME_QUEUE_NAME"
);

Now on the command line I am able to set queue options with imqcmd. For example

imqcmd -u admin -passfile ../password.txt update dst -n SOME_QUEUE_NAME -t q -o maxBytesPerMsg=-1 -f

Is there a way to achieve the same with an embedded Glassfish server?

Was it helpful?

Solution

Instead of using imqcmd, you can use the asadmin subcommand create-jmsdest to create a JMS physical destination.

From the documentation on create-jmsdest:

Typically, you use the create-jms-resource subcommand to create a JMS destination resource that has a Name property that specifies the physical destination. The physical destination is created automatically when you run an application that uses the destination resource. Use the create-jmsdest subcommand if you want to create a physical destination with non-default property settings.

If you do not specify a Name property for create-jms-resource, the name of the physical destination has the same name as the destination resource (replacing any forward slash in the JNDI name with an underscore).

Thus, the asadmin commands you want to run are for example:

create-jms-resource --restype javax.jms.Queue org/example/foo/SomeQueue
create-jmsdest --desttype queue --property maxBytesPerMsg=-1:maxTotalMsgBytes=-1 org_example_foo_SomeQueue

Note that (unlike imqcmd update dst) create-jmsdest does not update the properties if the resource already exists. Therefore, you should not start your application inbetween the two commands, otherwise the resource is automatically created with default properties.

If you have to update properties, you can remove the physical destination first using e.g. asadmin delete-jmsdest org_example_foo_SomeQueue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top