Package com.safmq

This package contains objects for communicating with the SAFMQ message queue server.

See:
          Description

Class Summary
ActorPermissions This mutable object represents an Actor's Permissions when interacting with SAFMQ.
ClientInfo Details about a client connection
CursorHandle This mutable object represents a handle to a cursor.
MessageQueue This class represents a SAFMQ message queue by providing a facade in front of the MQConnection.
MQBuilder A static builder class which builds connections to SAFMQ servers and message queues.
MQConnection This class provides an interface to communicate with a SAFMQ message queue server.
QueueHandle Represents a reference to s SAFMQ queue via the MQConnection class.
QueueMessage Represents a message to be sent or retrieved from a SAFMQ message queue server.
QueueStatistics Set of queue performance statistics.
Safmq Defines constants for use in the com.safmq package.
UUID An object to represent a universally unique identifier (UUID).
X509Identity Represents an identity presented by an X509 Digital Certificate
 

Exception Summary
MQException Exception thrown in cases where the SAFMQ queue server has responded with an error code from within a constructor.
 

Package com.safmq Description

This package contains objects for communicating with the SAFMQ message queue server. The com.safmq API is enteded to be full course communications package for use with the SAFMQ message queue server. As such it entails all the capabilities that the SAFMQ server provides. The primary class MQConnection facilitates communication and provides the API for Queue Reading and Writing; Queue Management; User Management; and Security Group Management.

Additionaly a facade class has been provided for easier access in queue reading and writing. This class, MessageQueue exists so that programs need not be concerned with security management concerns and can instead strictly read from and write to the queues. Additionally, a builder class, MQBuilder has been provided which constructs MessageQueue and MQConnection classes from a URL string and login credentials.

Round Trip Messaging

Examples of round trip messageing have been provided:

SAFMQ JMS Notes

JMS 1.1 Example

import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueBrowser;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;


public class SafmqJMSTest {
    public static void main(String[] args) throws Exception {
        Hashtable environment = null;
        
        environment = new Hashtable();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, com.safmq.jms.InitialContextFactory.class.getName());
        environment.put(Context.PROVIDER_URL, "safmq://localhost");
        environment.put(Context.SECURITY_PRINCIPAL, "admin");
        environment.put(Context.SECURITY_CREDENTIALS, "");
        
        Context ctx = new InitialContext(environment);
        
        ConnectionFactory   cf = (ConnectionFactory)ctx.lookup("ConnectionFactory");
        Queue               q = (Queue)ctx.lookup("testQ");
        Connection          con = cf.createConnection();
        Session             session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueBrowser        qb = session.createBrowser(q);
        Message             m;
        
        MessageProducer     mp = session.createProducer(q);
        TextMessage         tm = session.createTextMessage();
        
        tm.setStringProperty("label", "my label");
        tm.setText("Hello World");
    
        // Send the same message to the server 3 times    
        mp.send(tm);
        mp.send(tm);
        mp.send(tm);
    
        // List all the messages on the queue
        Enumeration e = qb.getEnumeration();
        while (e.hasMoreElements()) {
            m = (Message)e.nextElement();
            System.out.println("id:    " + m.getJMSMessageID());
            System.out.println("label: " + m.getStringProperty("label"));
            System.out.println("date:  " + (new Date(m.getJMSTimestamp())));
        }
        
        System.out.println("=============================================");
        // Dequeue all the messages on the queue
        MessageConsumer c = session.createConsumer(q);
        while (true) {
            m = c.receiveNoWait();
            if (m == null)
                break;
            System.out.println("id:    " + m.getJMSMessageID());
            System.out.println("label: " + m.getStringProperty("label"));
            System.out.println("date:  " + (new Date(m.getJMSTimestamp())));
            System.out.println("Text:  " + ((TextMessage)m).getText());
        }
        ctx.close();
    }
}

License

   Copyright 2005-2007 Matthew J. Battey

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

        Unless required by applicable law or agreed to in writing, software distributed
        under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
        CONDITIONS OF ANY KIND, either express or implied. See the License for the
        specific language governing permissions and limitations under the License.


This software implements a Java interface to SAFMQ (see http://safmq.sourceforge.net).

See Also:
MQBuilder, MQConnection, MessageQueue

Copyright Matthew J. Battey, 2004-2010;
Powered By: Get SAFMQ: Store and Forward Message Queue at SourceForge.net. Fast, secure and Free Open Source software downloads