Search This Blog

Thursday, May 26, 2016

Apply patch on weblogic

To apply patches released by weblogic, extract the packages from the Oracle support site to your folder.

Go to command prompt and appent OPatch path to the path variable in the windows variable.

Set PATH=%PATH%;E:\setups\wls12210\OPatch

Set ORACLE_HOME = E:\setups\wls12210

Navigate to the patch root folder and run

Opatch lsinventory  and you should see the list of inventory



If everything is set correctly you will see the list of packages installed.

>Opatch apply

And it will apply the package.









Add custom jms properties in the header - weblogic

To add custom jms properties in jms header you need to add string property to the Text message.



                      Context ctx = new InitialContext(env);
                            //ctx.lookup("CreateVASErrorQ20");
                      QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory1"); //Connection Factory JNDI

                      QueueConnection con = factory.createQueueConnection();

                      QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

                      Queue queue = (Queue) ctx.lookup("Queue1"); //Find the Queue

                      QueueSender sender = session.createSender(queue); //Instantiating the message sender

                      TextMessage message = session.createTextMessage("Message sent again");
                            
                      message.setStringProperty("system", "prod");
                      con.start();

                     sender.send(message);


This will appear in the message like


Wednesday, May 25, 2016

Create jms on Weblogic 12c (OSB) cluster–JMS servers health not up.

 

bug #  21830665.

Version 12.2.1.0.0

21830665: HEALTH CHECK RESULT OF JMS SERVERS ARE LEFT BLANK

JMS infrastructure on above versions of weblogic using OSB 12c  will not work untill the patch 21830665 is applied.

Once the patch is applied , follow the configuration below to make it work.

Create a cluster.

A cluster will contain two managed servers ms1 and ms2 and cluster name is mycluster(select unicast mode of messaging)

image

Both ms have different ports and are started by going to domains/bin startManagedServer.cmd ms1 (press enter and username/pwd  when asked)

image

Get your cluster up and running.

Now go to JMS servers and create two new jms servers pointing to both managed servers ms1 and ms2.

JMServer1 and JMServer2 both pointed to two managed servers.(JMS servers act as containers for the JMS infrastructure and are mapped directly to either managed servers or the clusters)

image

Use filestore for both of the jms servers.

 

Now go to JMS modules

Create a jms module called clusterjmsmodule, in targets select the cluster so that jms servers under that clusters are available for subdeployment mapping of other jms resources in this module.

Create a connection factory and map it to the cluster.

Create queue1 and create a sub-deployment and select the first jms server, similarly create another queue and map it to the other jmsserver.

image

JMS Server health should be green after this configuration is complete and you should be able to see monitoring tab in the queues.

 

Use a program in eclipse to send message to queueu and see the count of messages in monitoring tab of queue.

Use this link bottom line code ,  to find out how to send messages to a queue via code.

image

 

 

P.S File store statistics should be available if the JMS servers are up and running fine.

Create jms bridge in weblogic

Jms bridge is like a forwarder which is used between two different versions or domains of weblogic and is used to forward messages from one destination(queues) to another destination(queue)

To create a bridge between two weblogics W1 and W2 you will have to create two destinations.
Bridge source is going to be your source queue on W1 and destination is going to be the target queue on the W2 server.

image

Source destination looks like this
image

Q3 is my local queueu in W1.

Now create bridge destination
image

Now use this code to send message to the q3 on W1 and it should forward to queue4 on W2

////////////////////


    import javax.jms.*;
import javax.naming.*;

    public class Consumer {
        /**
         * Main method.
         *
         * @param args     the destination used by the example
         *                 and, optionally, the number of
         *                 messages to send
         */
       
        static java.util.Hashtable env;
        public static void main(String[] args) {
            final int NUM_MSGS;
           /* if ((args.length < 1) || (args.length > 2)) {
                System.out.println("Program takes one or two arguments: " +
                    "<dest_name> [<number-of-messages>]");
                System.exit(1);
            }*/
            // String destName = new String(args[0]);
           
          
            /*
             * Create a JNDI API InitialContext object if none exists
             * yet.
             */
            Context jndiContext = null;
            try {
               
               
               
               
                env = new java.util.Hashtable();
                env.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
               
                System.out.println("-- ok 1 -- ");
               
                /*env.put("java.naming.provider.url", "t3://10.105.98.8:7001");
                env.put("java.naming.security.principal", "weblogic");
                env.put("java.naming.security.credentials", "weblogic");
                */
                env.put("java.naming.provider.url", "t3://localhost:7004");
                env.put("java.naming.security.principal", "weblogic");
                env.put("java.naming.security.credentials", "weblogic@123");
               
                System.out.println("-- ok 2 -- ");
               
                jndiContext = new InitialContext(env);
              //  jndiContext.lookup("weblogic.jndi.WLInitialContextFactory");
               
               
                System.out.println(" jndiContext - " + jndiContext);
               
            } catch (NamingException e) {
                System.out.println("Could not create JNDI API context: " +
                    e.toString());
                System.exit(1);
            }
            /*
             * Look up connection factory and destination.  If either
             * does not exist, exit.  If you look up a
             * TopicConnectionFactory or a QueueConnectionFactory,
             * program behavior is the same.
             */
            ConnectionFactory connectionFactory = null;
            Destination dest = null;
            try {
                System.out.println(" -- ok 3 -- ");
               
                          
               
            //    System.out.println("Lookup done----------  " +   obj);
               
               
               
                Context ctx = new InitialContext(env);
                    //ctx.lookup("CreateVASErrorQ20");
                QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory1"); //Connection Factory JNDI
                QueueConnection con = factory.createQueueConnection();
                QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                Queue queue = (Queue) ctx.lookup("Queue1"); //Find the Queue
                QueueSender sender = session.createSender(queue); //Instantiating the message sender
                TextMessage message = session.createTextMessage("Message sent again");
                      
                con.start();
               sender.send(message);
               System.out.println(" -- Message sent -- ");
               
               
              // Now receiving the message:
                int count = 0 ;
               
                QueueReceiver receiver = session.createReceiver(queue);
              while(true) {
                  TextMessage receivedMessage = (TextMessage)receiver.receiveNoWait();
                if(receivedMessage != null) {
                if(receivedMessage instanceof javax.jms.TextMessage) {
              
               
               
                System.out.println("Received message = " + receivedMessage);
               
                System.out.println(" -- Message Received -- "+receivedMessage.getJMSMessageID());
               
                count++;
                } /*else {
                break;
                }*/
                }
                }
               
               
              
               
            //    System.out.println(" -- Message Received -- "+receivedMessage.getJMSMessageID());
               
               
                /*connectionFactory = (ConnectionFactory) jndiContext.lookup("PrepaidActValDS");
                dest = (Destination) jndiContext.lookup(destName);
                System.out.println( "dest "+ dest);*/
               
            } catch (Exception e) {
                System.out.println("JNDI API lookup failed: " + e.toString());
                e.printStackTrace();
                //System.exit(1);
            }
            /*
             * Create connection.
             * Create session from connection; false means session is
             * not transacted.
             * Create producer and text message.
             * Send messages, varying text slightly.
             * Send end-of-messages message.
             * Finally, close connection.
             */
           // Connection connection = null;
           // MessageProducer producer = null;
//            try {
//                connection = connectionFactory.createConnection();
//
//                Session session =
//                    connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
//                producer = session.createProducer(dest);
//
//                TextMessage message = session.createTextMessage();
//
//                for (int i = 0; i < NUM_MSGS; i++) {
//                    message.setText("This is message " + (i + 1));
//                    System.out.println("Sending message: " + message.getText());
//                    producer.send(message);
//                }
//
//                /*
//                 * Send a non-text control message indicating end of
//                 * messages.
//                 */
//                producer.send(session.createMessage());
//            } catch (JMSException e) {
//                System.out.println("Exception occurred: " + e.toString());
//            } finally {
//                if (connection != null) {
//                    try {
//                        connection.close();
//                    } catch (JMSException e) {
//                    }
//                }
//            }
        }
    }