通用的做法是用socket联系起在本地的两个应用。

解决方案 »

  1.   

    连message queue都不支持,那在linux下移植起c写的程序不是很麻烦。
      

  2.   

    using JMS: Java Message Service
      

  3.   

    Sun有一个免费的MQ可以拿来用
      

  4.   

    难道没有基于操作系统的消息队列的实现方式么,我看了jms的文档,这是基于中间件的。
      

  5.   

    可是自己写实现msqQueuepublic class msqQueue
    {
    /** Table for storing the message queues */
    Hashtable ivQueueTable = new Hashtable(); /**
     * Insert the method's description here.
     * Creation date: (2000/06/13 11:20:17 AM)
     * @return java.lang.String
     */
    public synchronized HashMap getAllQueueLen()
    {
    HashMap lvQueueLenMap = new HashMap(); Iterator lvIter = ivQueueTable.keySet().iterator(); while (lvIter.hasNext())
    {
    String lvProcessorName = (String)lvIter.next();
    try
    {
    int lvLen = getQueueLength(lvProcessorName);
    lvQueueLenMap.put(lvProcessorName, new Integer(lvLen));
    }
    catch (Exception lvException)
    {}
    } return lvQueueLenMap;
    } /**
    * Gets the number of priority queue
    * @param pQueueName is the name of the message queue
    * @return Returns the number of priority queue
    */
    public int getMaximumPriorityQueueSize(String pQueueName) throws Exception
    {
    msqQueueElement lvQueue = (msqQueueElement)ivQueueTable.get(pQueueName);
    // Check whether the request queue is registered or not
    // if the queue is not registered, exception will be thrown
    if (lvQueue == null)
    throw new errQueueNotFoundException(pQueueName); return lvQueue.getMaximumPriorityQueueSize();
    } /**
    * Gets message from the message queue
    * @param pQueueName is the name of the message queue
    * @return Returns the message extracted from the message queue
    */
    public Object getMessage(String pQueueName) throws Exception
    {
    msqQueueElement lvQueue = (msqQueueElement)ivQueueTable.get(pQueueName);
    // Check whether the request queue is registered or not
    // if the queue is not registered, exception will be thrown
    if (lvQueue == null)
    throw new errQueueNotFoundException(pQueueName); return lvQueue.get();
    } /**
    * Gets the current queue length of the message queue
    * @param pQueueName is the name of the message queue
    * @return Returns the total number of message queued in the message queues
    */
    public int getQueueLength(String pQueueName) throws errQueueNotFoundException
    {
    msqQueueElement lvQueue = (msqQueueElement)ivQueueTable.get(pQueueName);
    // Check whether the request queue is registered or not
    // if the queue is not registered, exception will be thrown
    if (lvQueue == null)
    throw new errQueueNotFoundException(pQueueName); return lvQueue.getQueueLength();
    }
    /**
    * Posts the message to the destination queue
    * @param pQueueName is the name of the message queue
    * @param pMessage is the message that needs to be queued
    */
    public void postMessage(String pQueueName, Object pMessage) throws errQueueNotFoundException
    {
    msqQueueElement lvQueueElement = (msqQueueElement)ivQueueTable.get(pQueueName);
    if (lvQueueElement != null)
    lvQueueElement.put(pMessage);
    else
    throw new errQueueNotFoundException(pQueueName);
    }
    /**
    * Posts the message to the destination queue with priority
    * @param pQueueName is the name of the message queue
    * @param pMessage is the message that needs to be queued
    * @param pPriority is the priority of the queue
    */
    public void postMessage(String pQueueName, Object pMessage, int pPriority) throws errQueueNotFoundException
    {
    msqQueueElement lvQueueElement = (msqQueueElement)ivQueueTable.get(pQueueName);
    if (lvQueueElement != null)
    lvQueueElement.put(pMessage, pPriority);
    else
    throw new errQueueNotFoundException(pQueueName);
    }
    /**
     * Insert the method's description here.
     * Creation date: (2000/06/13 11:20:17 AM)
     * @return java.lang.String
     */
    public void printAllQueueLen()
    {
    String lvResult = "";
    TreeMap lvQueueLenMap = new TreeMap(getAllQueueLen()); Iterator lvIter = lvQueueLenMap.keySet().iterator();
    while (lvIter.hasNext())
    {
    String lvProcessorName = (String)lvIter.next(); Integer lvLen = (Integer) lvQueueLenMap.get(lvProcessorName); lvResult = lvResult + lvProcessorName + " = " + lvLen + "\r\n";
    } System.out.println(lvResult);
    }
    /**
    * Creates a message queue with default number of priority and registers it
    * @param pQueueName is the name of the message queue
    */
    public synchronized void registerQueue(String pQueueName) throws errQueueSizeException, errQueueAlreadyRegisteredException
    {
    if (ivQueueTable.containsKey(pQueueName))
    throw new errQueueAlreadyRegisteredException(pQueueName);
    msqQueueElement lvQueueElement = new msqQueueElement();
    ivQueueTable.put(pQueueName, lvQueueElement);
    }
    /**
    * Creates a message queue with user defined number of priority and registers it
    * @param pQueueName is the name of the message queue
    * @param pPriorityQueueSize is the size of the priority queue
    */
    public synchronized void registerQueue(String pQueueName, int pPriorityQueueSize) throws errQueueSizeException
    {
    msqQueueElement lvQueueElement = new msqQueueElement(pPriorityQueueSize);
    ivQueueTable.put(pQueueName, lvQueueElement);
    }
    /**
    * Destroys the specified message queue
    * @param pQueueName is the name of the message queue
    */
    public synchronized void unregisterQueue(String pQueueName)
    {
    if (ivQueueTable.containsKey(pQueueName))
    ivQueueTable.remove(pQueueName);
    }
    }