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?
Instead of using
imqcmd, you can use theasadminsubcommandcreate-jmsdestto create a JMS physical destination.From the documentation on
create-jmsdest: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
asadmincommands you want to run are for example:Note that (unlike
imqcmd update dst)create-jmsdestdoes 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.