[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 758
  • Last Modified:

javax.jms.InvalidClientIDException: Duplicate clientID

hi,

i am running this wrox example on point to point JMS, i keep on

getting the following error:

C:\wrox\pro_jms\Chapter04>java ptp.onlinebanking.AccountingPanel
javax.jms.InvalidClientIDException: Duplicate clientID: BANK1000
        at
org.exolab.jms.server.ServerConnectionManagerImpl.addClientID(ServerC
onnectionManagerImpl.java:270)
        at

org.exolab.jms.server.ServerConnectionImpl.setClientID(ServerConnecti
onImpl.java:208)
        at

org.exolab.jms.server.net.RemoteServerConnection.setClientID(RemoteSe
rverConnection.java:157)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native

Method)
        at

sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at

org.exolab.jms.net.orb.DefaultORB$Handler.invoke(DefaultORB.java:572)

        at

org.exolab.jms.net.orb.DefaultORB$1.run(DefaultORB.java:530)
        at

org.exolab.jms.common.threads.ThreadPool$NotifyingRunnable.run(Thread
Pool.java:211)
        at

EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown So
urce)
        at java.lang.Thread.run(Thread.java:619)

the source code is as follows:

AccountingPaenl

package ptp.onlinebanking;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class AccountingPanel extends Applet
 implements ItemListener, ActionListener, DisplayHandler  {
 
 Choice routingNumberChoice;
 TextArea displayArea;
 Button quitButton;
 
 AccountsDepartment accounting;

 public void init() {
 
  accounting = new AccountsDepartment

(AccountsDepartment.PROVIDER_URL,
                                       AccountsDepartment.USER_NAME,
                                       AccountsDepartment.PASSWORD);
  accounting.setParent (this);
 
  routingNumberChoice = new Choice ();
  routingNumberChoice.addItem (Instruction.ECOMMWARE_BANK_NO);
  routingNumberChoice.addItem (Instruction.HERITAGE_BANK_NO);
  routingNumberChoice.addItem (Instruction.RAJ_BANK_NO);  
 
  displayArea = new TextArea (15,50);
  displayArea.setEnabled(false);
  displayArea.setText ("Before Proceeding, Set up the Receiver:\n"+
                       "Select a Bank from the Choice above ...");
 
  quitButton = new Button ("Close Connections");
 
  this.setLayout (new BorderLayout ());
 
  add(routingNumberChoice, BorderLayout.NORTH);
  add(displayArea, BorderLayout.CENTER);
  add(quitButton, BorderLayout.SOUTH);
 
  routingNumberChoice.addItemListener (this);
  quitButton.addActionListener (this);
 }

public synchronized void appendData (String data) {
  displayArea.append (data+"\n\r");
 }

 public void itemStateChanged(ItemEvent itemEvent) {
 
  String choice = (String) itemEvent.getItem();
  accounting.setRoutingNumber (choice);
  accounting.initialize ();
  accounting.createConnections ();
  accounting.process ();
  routingNumberChoice.setEnabled (false);
  displayArea.setText ("");
 }  

public void actionPerformed (ActionEvent actionEvent) {

  if (actionEvent.getSource () == quitButton) {
   accounting.closeConnections ();
   System.exit (0);
  }
 }

public static void main(String[] args) {
  AccountingPanel panel = new AccountingPanel ();
  panel.init ();
  Frame frame = new Frame ("Bank Accounting Department");
  frame.add (panel,BorderLayout.CENTER);
  frame.setSize (250,250);
  frame.setLocation(300,200);
  frame.pack ();
  frame.show ();
 }
}


AccountingDepartment
package ptp.onlinebanking;

import common.*;
import javax.jms.*;

import java.util.*;

public class AccountsDepartment {
 
 private String bankNumber;
 private QueueConnectionFactory factory;
 private QueueConnection connection;
 private javax.jms.Queue requestQueue, orderQueue;
 private QueueSession session, transactionalSession;
 private QueueReceiver receiver, queueReceiver;
 private QueueSender sender;
 
 private String hostName;
 private String userID;
 private String password;
 
 private DisplayHandler parent;

 private static final String CONTEXT_FACTORY =

"org.exolab.jms.jndi.InitialContextFactory";

//"fiorano.jms.rtl.FioranoInitialContextFactory";
      private static final String CONNECTION_FACTORY =

"JmsQueueConnectionFactory";
 private static final String REQUEST_RECEIVER_QUEUE =

"bank:accounts";  
 private static final String ORDER_RECEIVER_QUEUE =

"bank:clearing_house";  
 
 //static final String PROVIDER_URL = "127.0.0.1:2001";
      static final String PROVIDER_URL = "rmi://localhost:1099/";
 static final String USER_NAME = "athul";
 static final String PASSWORD = "raj";

 public AccountsDepartment (String host,
                            String ID,
                            String passwd) {
  hostName = host;
  userID = ID;
  password = passwd;
 }
 
 private AccountsDepartment () {
  hostName = PROVIDER_URL;
  userID = USER_NAME;
  password = PASSWORD;  
 }

public void initialize () {
  try {
   JNDIService.init (CONTEXT_FACTORY, hostName);
   factory = (QueueConnectionFactory)JNDIService.lookup

(CONNECTION_FACTORY);  
   requestQueue = (javax.jms.Queue)JNDIService.lookup

(REQUEST_RECEIVER_QUEUE);  
   orderQueue = (javax.jms.Queue)JNDIService.lookup

(ORDER_RECEIVER_QUEUE);  
  }
  catch (Exception exception) {
   exception.printStackTrace ();
  }
}

public void createConnections () {
  try {
   connection = factory.createQueueConnection();
   System.out.println("setClientID");
   connection.setClientID (bankNumber);
   
   session = connection.createQueueSession(false,
                                           Session.AUTO_ACKNOWLEDGE);
   transactionalSession=connection.createQueueSession(true,
                                                   

Session.AUTO_ACKNOWLEDGE);  
  }
  catch (Exception exception) {
   exception.printStackTrace ();
  }  
 }

 public void closeConnections () {
  try {

   if (sender != null) sender.close ();
   if (receiver != null) receiver.close ();
   if (queueReceiver != null) queueReceiver.close ();
   if (session != null) session.close ();
   if (transactionalSession != null) transactionalSession.close ();
   if (connection != null) connection.close ();
  }
  catch (JMSException exception) {
   exception.printStackTrace ();
  }
 }

public void process () {
  try {
   createConnections ();
   // Create a Message Selector
   String messageSelector = "JMSCorrelationID = '"+ bankNumber +"'";
   // Create a javax.jms.Queue Receiver
   queueReceiver = transactionalSession.createReceiver(requestQueue,
                                                       

messageSelector);

   queueReceiver.setMessageListener(new RequestMessageListener (this,
                                                               

requestQueue,
                                                     

transactionalSession));
   
   receiver = transactionalSession.createReceiver (orderQueue,
                                                   messageSelector);
   receiver.setMessageListener(new TransferFundsListener (this,
                                                          orderQueue,
                                                     

transactionalSession));
   connection.setExceptionListener (new ExceptionHandler ());
   connection.start();  
   System.out.println ("Bank No. :"+bankNumber+
                       " up and ready for eCommerce ...");
  }
  catch (Exception exception) {
   exception.printStackTrace ();
  }    
 }

 boolean sendTransferFundsMessage (Instruction instruction)
  throws Exception {
  boolean result = true;
  if (null == instruction) return false;
  try {
   // Create a Sender if one does not exist
   if (sender == null) {
    sender = transactionalSession.createSender (orderQueue);
   }
   
   // create a Bytes Message
   BytesMessage bytesMessage =

transactionalSession.createBytesMessage();
   // set message properties
   bytesMessage.setStringProperty ("customerBank",
                                   instruction.getCustomerBank ());
   bytesMessage.setStringProperty ("accountNumber",
                                   instruction.getAccountNumber ());
   bytesMessage.setStringProperty ("customerName",
                                   instruction.getCustomerName ());
   bytesMessage.setStringProperty ("date", instruction.getDate ());
   bytesMessage.setStringProperty ("checkNumber",
                                   instruction.getCheckNumber ());
   bytesMessage.setStringProperty ("payeeName",
                                   instruction.getPayeeName ());
   bytesMessage.setDoubleProperty ("amount",
                                   instruction.getAmount ());
   bytesMessage.setStringProperty ("action", instruction.getAction

());
   bytesMessage.setStringProperty ("routingNumber",
                                   instruction.getRoutingNumber ());
   bytesMessage.setStringProperty ("payeeAccount",
                                   instruction.getPayeeAccount ());  
   bytesMessage.setJMSCorrelationID (instruction.getRoutingNumber

());
   
   // send the message
   sender.send (bytesMessage,
                DeliveryMode.PERSISTENT,
                Message.DEFAULT_PRIORITY,
                Message.DEFAULT_TIME_TO_LIVE);

   String display = instruction.getAction () +
                    " for Check No: "+
                    instruction.getCheckNumber ()+
                    " message, sent for "+
                    instruction.getRoutingNumber ()+
                    " through the javax.jms.Queue "+
                    orderQueue.getQueueName ();
   System.out.println (display);
   parent.appendData (display);
  }
  catch (Exception exception) {
   String display = instruction.getAction () +
                    " for Check No: "+
                    instruction.getCheckNumber ()+
                    " message, could not be sent for "+
                    instruction.getRoutingNumber ();
   System.out.println (display);  
   parent.appendData (display);
   exception.printStackTrace ();
   result = false;
   throw exception;
  }  
  return result;
 }

Vector browseQueueMessages (String accountNumber) {
  QueueBrowser browser = null;
  Enumeration enum1 = null;
  int count = 0;
  Instruction instruction = null;  
  Vector browserList = new Vector ();
  try {
   browser = session.createBrowser (orderQueue);
   enum1 = browser.getEnumeration();
   while (enum1.hasMoreElements() == true) {
    System.out.println ("Browser getting Message No. "+
                        ++count);
    BytesMessage msg = (BytesMessage) enum1.nextElement();
    if (msg != null) {
     instruction = new Instruction(msg.getStringProperty

("customerBank"),
                                   msg.getStringProperty

("accountNumber"),
                                   msg.getStringProperty

("customerName"),
                                   msg.getStringProperty ("date"),
                                   msg.getStringProperty

("checkNumber"),
                                   msg.getStringProperty

("routingNumber"),
                                   msg.getStringProperty

("payeeAccount"),
                                   msg.getStringProperty

("payeeName"),
                                   msg.getDoubleProperty ("amount"),
                                   msg.getStringProperty ("action"));
     if (instruction.getCustomerBank ().equals (bankNumber) &&
         instruction.getAccountNumber ().equals (accountNumber)) {
       instruction.print ();
       browserList.addElement (instruction);
     }
    }
   } // end while
   if (browser != null) browser.close ();  
  } // end try
  catch(Exception e) {
      e.printStackTrace();
  }    

  return browserList;
} // end of function browseQueueMessages()

    public void setRoutingNumber (String routingNumber) {
      bankNumber = routingNumber;
    }
 
    public void setParent (DisplayHandler applet) {
      parent = applet;
    }
 
    public void appendData (String data) {
      if (parent != null) {
          parent.appendData (data);
  }
 }
 
 public static void main(String[] args) {
  AccountsDepartment accounting = new AccountsDepartment ();
  accounting.setRoutingNumber (args[0]);
  accounting.initialize ();
  accounting.createConnections ();
  accounting.process ();
  System.out.println ("Accounts Department of Bank "+
                      args[0]+
                      " ... Ready to receive messages.");
 }




class ExceptionHandler implements ExceptionListener {
 
  public void onException (JMSException exception) {
   exception.printStackTrace ();
  }
 } // end ExceptionHandler class definition



} // end AccountsDepartment class definition

is there a way to not make clientid's permanent, and so that i can

set them explicitly in my program?  thanks.
0
mmingfeilam
Asked:
mmingfeilam
  • 2
1 Solution
 
CEHJCommented:
The same client appears to be connected more than once, which may not be allowed by the server
0
 
CEHJCommented:
:-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now