我试图用Java编写脚本以自动将文件传输到IBM MQ。请注意,即使我在另一端收到消息,我仍然希望该消息保留原始文件名。
基本上,我想要在Java中等效于此命令提示符:
-bash-4.1$ /opt/mqm/java/jre64/jre/bin/java -jar imqsput.jar --channel=REMOTE.ADMIN.... --host=.... --input=test/20190918_153009858_Test.txt --manager=... --port=1414 --queue=... &>> testoutput1.out
在这种情况下,必须保留文件名,因为应用程序稍后会从消息中读取该文件名。
到目前为止,我已经有了类似这样的标准:
import javax.jms.Connection;
import javax.jms.Session;
import javax.jms.Message;
import javax.jms.MessageProducer;
import com.ibm.jms.*;
import com.ibm.mq.jms.*;
MQConnectionFactory factory = new MQConnectionFactory();
factory.setHostName("tcp://.......");
factory.setPort(1414);
factory.setQueueManager(".......");
factory.setChannel("REMOTE.ADMIN........");
Connection connection = factory.createConnection("......", "........");
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
String content=vars.get("processedTestData");
MQQueue queue = (MQQueue) session.createQueue("queue:///.......");
MessageProducer producer = session.createProducer(queue);
Message message = session.createTextMessage(content);
producer.send(message);
connection.close();
但是,除了字符串内容之外,我想以与imqsput相同的方式发送文件。用Java做的任何方式吗?
imqsput的说明:
IMQsPUT allows loading files into IBM message queues.
-c,--channel <CHANNEL> The channel used to access the
queue. Alternatively can be
replaced by specifying a client
definition.
--ccsid <CCSID> The target encoding/charset/ccsid
to be used for messages being
written to the queue. The default
is '1208'.
The following CCSIDs can be used:
http://www-01.ibm.com/software/glo
balization/ccsid/ccsid_registered.
html
--charset <CHARSET> The charset to be used for reading
input files. The default is
'UTF-8'. The following values are
valid: 'US-ASCII', 'ISO-8859-1',
'UTF-8', 'UTF-16BE', 'UTF-16LE',
'UTF-16'.
--cipher-suite <SUITE> The cipher suite for the secure
connections.
-d,--definition <URL> URL to the client channel
definition (CCDT). Must include
the protocol like file:///. If
this is not set, then the host,
post and channel parameters must
be set.
-h,--host <HOST> The hostname/IP address of the
machine hosting the queues.
-i,--input <FILE1/PATH1,FILE2/PATH2> A comma separated list of files
and directories which should be
loaded onto the queue.
--keystore-file <FILE> Sets the keystore, used for secure
connections.Establishes a secure
connection to the queue.
--keystore-password <PASSWORD> Optional password for the keystore
to be used with the
--keystore-file option.
-m,--manager <MANAGER> The name of the queue manager.
Alternatively can be replaced by
specifying a client definition.
-p,--port <PORT> The port used to access the queue
manager. If not set 1414 is used.
Alternatively can be replaced by
specifying a client definition.
-q,--queue <QUEUE> The name of the Queue.
-r,--remove-original Deletes the original input file
when it was successfully written
to the queue.
-R,--rename-failed <EXTENSION> When set, files which failed to
transmit will be renamed by
appending the given extension to
the filename. Files which already
have this extension will not be
processed again (only relevant
when transmitting a folder).
--ssl-debug If this is enabled, then a SSL
trace will be generated.
--truststore-file <FILE> Sets the truststore, used for
secure connections.
--truststore-password <PASSWORD> Optional password for the
truststore to be used with the
--truststore-file option
-u,--unique-message-id When set, the message ID is set to
a randomly generated String,
otherwhise, the filename is used.
Class diagram for imqsput
最佳答案
DOgl,如果我理解正确,则希望将文件作为消息发送到队列中,或者相反。那么,您是否尝试过使用与IBM MQ捆绑在一起的MQ的托管文件传输功能?这将解决您的情况。
关于java - 如何编写Java代码以将文件传输到保留文件名的IBM MQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62426738/