1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the License). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/CDDL.txt 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/CDDL.txt. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets [] replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 */ 27 28 #pragma ident "@(#)create_tdq.c 1.4 07/08/07 SMI" 29 30 #include <stdio.h> 31 #include <stdlib.h> 32 #include <string.h> 33 #include <cmqc.h> 34 35 int 36 main(int argc, char **argv) 37 { 38 MQOD od = {MQOD_DEFAULT}; 39 MQMD md = {MQMD_DEFAULT}; 40 MQPMO pmo = {MQPMO_DEFAULT}; 41 MQHCONN Hcon; 42 MQHOBJ Hobj; 43 MQLONG CompCode; 44 MQLONG Reason; 45 MQLONG CReason; 46 MQLONG messlen; 47 MQLONG O_options; 48 char buffer[100]; 49 char QMName[50]; 50 51 if (argc < 2) { 52 (void) printf("Missing Queue Manager Name \n"); 53 exit(99); 54 } 55 56 /* Setup the Object Descriptor */ 57 (void) strcpy(od.ObjectName, "SYSTEM.DEFAULT.MODEL.QUEUE"); 58 (void) strcpy(QMName, argv[1]); 59 (void) strcpy(od.DynamicQName, "*"); 60 (void) strcpy(buffer, "Test message for temp dynamic queue"); 61 62 /* Connect to the Queue Manager */ 63 MQCONN(QMName, 64 &Hcon, 65 &CompCode, 66 &CReason); 67 68 if (CompCode == MQCC_FAILED) { 69 (void) printf("MQCONN ended with reason code %d\n", CReason); 70 exit((int)CReason); 71 } 72 73 /* Replace newline with null and reduce messlen */ 74 messlen = (MQLONG)strlen(buffer); 75 if (buffer[messlen-1] == '\n') { 76 buffer[messlen-1] = '\0'; 77 --messlen; 78 } 79 80 /* 81 * Set the Message Descriptor and Put Message Options 82 * md.MsgType - Message, reply not required 83 * md.Persistence - Not persistent for tdq 84 * md.Format - Character string 85 * md.Msgid - No message id 86 * md.CorrelId - No correlation id 87 * pmo.Options - Fail if the qmgr is quiescing 88 */ 89 90 md.MsgType = MQMT_DATAGRAM; 91 92 md.Persistence = MQPER_NOT_PERSISTENT; 93 94 (void) memcpy(md.Format, MQFMT_STRING, (size_t)MQ_FORMAT_LENGTH); 95 96 (void) memcpy(md.MsgId, MQMI_NONE, sizeof (md.MsgId)); 97 98 (void) memcpy(md.CorrelId, MQCI_NONE, sizeof (md.CorrelId)); 99 100 pmo.Options = MQPMO_FAIL_IF_QUIESCING; 101 102 O_options = MQOO_OUTPUT | MQOO_FAIL_IF_QUIESCING; 103 104 /* Open the Queue */ 105 MQOPEN(Hcon, 106 &od, 107 O_options, 108 &Hobj, 109 &CompCode, 110 &Reason); 111 112 if (Reason != MQRC_NONE) { 113 (void) printf("MQOPEN ended with reason code %d\n", Reason); 114 exit((int)Reason); 115 } 116 117 /* Put the Message */ 118 MQPUT1(Hcon, 119 &od, 120 &md, 121 &pmo, 122 messlen, 123 buffer, 124 &CompCode, 125 &Reason); 126 127 if (Reason != MQRC_NONE) { 128 (void) printf("MQPUT1 ended with reason code %d\n", Reason); 129 exit((int)Reason); 130 } 131 132 /* Disconnect from the Queue Manager */ 133 if (CReason != MQRC_ALREADY_CONNECTED) { 134 MQDISC(&Hcon, 135 &CompCode, 136 &Reason); 137 138 if (Reason != MQRC_NONE) { 139 (void) printf("MQDISC ended with reason code %d\n", 140 Reason); 141 exit((int)Reason); 142 } 143 } 144 145 return (0); 146 } 147