Messaging: Send JMS message

XQuery code example to demonstrate how to send JMS messages.

Warning! For this function the user must be 'dba' or he must be in the 'jms' group.
(:
 : Example: send 10 JMS messages with a few message properties
 :)
xquery version "3.0";



import module namespace messaging="http://exist-db.org/xquery/messaging" 
              at "java:org.exist.jms.xquery.MessagingModule";



(: Configuration for setting-up an JMS connection :)
let $jmsConfiguration :=
    map {
        "java.naming.factory.initial" 
            := "org.apache.activemq.jndi.ActiveMQInitialContextFactory",
        "java.naming.provider.url" := "tcp://localhost:61616",
        "destination" := "dynamicQueues/eXistdb-messaging-demo",
        "connection-factory" := "ConnectionFactory"
    }
 
(: JMS message properties :)
let $messageProperties :=
    map {
        "Su" := "Sunday",
        "Mo" := xs:integer(1),
        "Tu" := 2,
        "We" := true(),
        2 := "a",
        "test" := (1,2,3,4,5), (: not transferred :)
        "a" := xs:short(5)      
    }


return
    
    for $i in (1 to 10)
    
    (: The actual message payload :)
    let $content := <data>{$i}</data>
    
    return
    
        (: Send message to the JMS broker :)
        messaging:send( $content , $messageProperties, $jmsConfiguration )