Welcome, guest | Sign In | My Account | Store | Cart

Put messages on remote MQ Series queue using IBM implementation of Java Messaging Service Specification.

Tcl, 123 lines
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
###########################################################
# Connect to MQ listener and put message on the queue.
###########################################################

puts "\n executing [info script]\n"

# make script drive independent.

set drive [lindex [file split [info nameofexecutable]] 0 ] 

puts "\n proclib = $drive/scripts/TCL/proclib"

########################################################  
# Source packages. 
########################################################  

package require java

######################################
# Proc - check mq listener. 
######################################
proc checkMQ { QManager CCSID channel hostname queueName port traceFile msg } {

   puts "\n checkMQ \n"

   # import required classes 
   java::import com.ibm.mq.jms.MQQueueConnectionFactory
   java::import com.ibm.mq.jms.services.ConfigEnvironment
   java::import com.ibm.mq.jms.JMSC
   java::import com.ibm.mq.jms.MQQueueSession
   java::import com.ibm.mq.jms.MQQueueSender

   # instanciate MQQueueConnectionFactoryI object.
   set MQQueueConnectionFactoryI [ java::new MQQueueConnectionFactory ]

   # set MQQueueConnectionFactory instance methods.
   $MQQueueConnectionFactoryI setQueueManager         $QManager
   $MQQueueConnectionFactoryI setPort                 $port
   $MQQueueConnectionFactoryI setHostName             $hostname
   $MQQueueConnectionFactoryI setChannel              $channel
   $MQQueueConnectionFactoryI setCCSID                $CCSID
   $MQQueueConnectionFactoryI setUseConnectionPooling true
   $MQQueueConnectionFactoryI setTransportType        [ java::field JMSC MQJMS_TP_CLIENT_MQ_TCPIP ]    

   # set tracing on.
   java::call ConfigEnvironment start
   
   puts "Creating a Connection...................\n"

   set connectionI [ $MQQueueConnectionFactoryI createQueueConnection ]

   puts "Starting the Connection.................\n"

   $connectionI start

   puts "Creating a Session......................\n"

   set transacted      false 
   set autoAcknowledge [ java::field MQQueueSession AUTO_ACKNOWLEDGE ]
   set sessionI        [ $connectionI createQueueSession $transacted $autoAcknowledge ]

   puts "Creating a queue......................\n"

   set queueI         [ $sessionI createQueue $queueName ]

   puts "Creating a queue sender ......................\n"

   set queueSenderI  [ $sessionI createSender $queueI ] 

   puts "Sending the message to..[ $queueI getQueueName ]\n" 

   puts "Creating a TextMessage........................\n"

   set outMsgI [ $sessionI createTextMessage ]

   $outMsgI    setText $msg

   puts "Sending TextMessage \"$msg\" \n"

   $queueSenderI send $outMsgI
   
   puts "Closing QueueSender........................\n"

   $queueSenderI close 

   puts "Closing Session............................\n"

   $sessionI close 

   puts "Closing Connection.........................\n"

   $connectionI close 

}
######################################
# Main Control.
######################################

# build tcl classpath

append x $drive/IBM/WebSphereMQ/Java/lib/com.ibm.mq.jar\;
append x $drive/IBM/WebSphereMQ/Tools/Java/base\;
append x $drive/IBM/WebSphereMQ/Java/lib/com.ibm.mqjms.jar\;
append x $drive/IBM/WebSphereMQ/Tools/Java/jms\;
append x $drive/IBM/WebSphereMQ/Java/lib/com.ibm.mqbind.jar\;

set env(TCL_CLASSPATH) $x

puts "\nTCL_CLASSPATH = [ array get env TCL_CLASSPATH ]\n"

set traceFile    $drive/IBM/WebSphereMQ/Errors/mqTrace.txt
set reportFile   $drive/reports/notify/mqConnect.txt
set reportFileId [ open $reportFile w ] 

set QManager  YourQueueManager
set CCSID     819
set channel   your.channel.definition
set hostname  mqHost
set queueName your.queue.name
set port      1414
set msg       "Watson, please come here. I want you."

checkMQ $QManager $CCSID $channel $hostname $queueName $port $traceFile $msg 

Tcl Application access to JMS interface.

Created by Patrick Finnegan on Mon, 17 Oct 2005 (MIT)
Tcl recipes (162)
Patrick Finnegan's recipes (56)

Required Modules

  • (none specified)

Other Information and Tasks