Here's the code which is basically the producer examples as shipped w/
openmq. What domain.xml file are you referring to in glassfish? I never added
this file. MQStatus producer(char *dname, MQDestinationType dtype) { MQStatus
status; MQSessionHandle session_handle = MQ_INVALID_HANDLE;
MQDestinationHandle dhandle = MQ_INVALID_HANDLE; MQProducerHandle
producer_handle = MQ_INVALID_HANDLE; MQMessageHandle message_handle =
MQ_INVALID_HANDLE; MQ_ERR_CHK(MQCreateSession(g_conn_handle, MQ_FALSE,
MQ_CLIENT_ACKNOWLEDGE, MQ_SESSION_SYNC_RECEIVE, &session_handle));
MQ_ERR_CHK(MQCreateDestination(session_handle, dname, dtype, &dhandle));
MQ_ERR_CHK(MQCreateMessageProducerForDestination(session_handle, dhandle,
&producer_handle)); MQ_ERR_CHK(MQFreeDestination(dhandle));
MQ_ERR_CHK(MQCreateTextMessage(&message_handle)); while(1) { char text[128];
printf("Enter a message to send:\n"); if (fgets(text, 128, stdin) == NULL) {
break; } if ((strlen(text) == 0)) { break; } printf("Sending message: %s\n",
text); MQ_ERR_CHK(MQSetTextMessageText(message_handle, text));
MQ_ERR_CHK(MQSendMessage(producer_handle, message_handle)); }
MQ_ERR_CHK(MQSetTextMessageText(message_handle, "END"));
MQ_ERR_CHK(MQSendMessage(producer_handle, message_handle));
MQ_ERR_CHK(MQFreeMessage(message_handle));
MQ_ERR_CHK(MQCloseConnection(g_conn_handle));
MQ_ERR_CHK(MQFreeConnection(g_conn_handle)); return status; out: { MQString
err_string = MQGetStatusString(status); fprintf(stderr, "producer(): Error:
%s\n", (err_string == NULL) ? "NULL" : err_string); MQFreeString(err_string);
} MQFreeMessage(message_handle); MQFreeDestination(dhandle);
MQCloseConnection(g_conn_handle); MQFreeConnection(g_conn_handle); return
status; } MQStatus create_connection(char *bhost, int bport) { MQStatus
status; MQPropertiesHandle props_handle = MQ_INVALID_HANDLE;
MQ_ERR_CHK(MQCreateProperties(&props_handle));
MQ_ERR_CHK(MQSetStringProperty(props_handle, MQ_BROKER_HOST_PROPERTY,
bhost)); MQ_ERR_CHK(MQSetInt32Property(props_handle, MQ_BROKER_PORT_PROPERTY,
bport)); MQ_ERR_CHK(MQSetStringProperty(props_handle,
MQ_CONNECTION_TYPE_PROPERTY, "TCP"));
MQ_ERR_CHK(MQCreateConnection(props_handle, "guest", "guest", NULL, NULL,
NULL, &g_conn_handle)); MQ_ERR_CHK(print_version()); return status; out: {
MQString err_string = MQGetStatusString(status); fprintf(stdout,
"create_connection(): Error: %s\n", (err_string == NULL) ? "NULL" :
err_string); MQFreeString(err_string); } MQFreeProperties(props_handle);
return status; } And here is where I call from my main function ... if
(MQStatusIsError(create_connection(bhost, bport))) { return 1; } if
(MQStatusIsError(producer(dname, dtype))) { return 1; }
--
[Message sent by forum member 'rrlangly']
View Post: http://forums.java.net/node/889973