java - 如何编写Java代码以将文件传输到保留文件名的IBM MQ

标签 java ibm-mq

我试图用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/

相关文章:

java - ArrayList 上的错误

java - Android Firebase - 无法从 Firebase 快照接收正确的 JSON

spring - 单点对点队列和多个监听器

java - 登录Facebook App并授权我的应用程序后,如何正确获取Access Token等信息? [安卓]

java - 无法使用 iText 将越南语字符导出到 PDF

java - 使用 JMS 的 WebSphere MQ

.net - 是否可以使用 .NET 和来自 Windows 证书存储的证书连接到 Websphere MQ?

size - 如何通过 JMS 向 WebSphere MQ 发送大消息?

activemq - 将本地 Active MQ 连接到远程 IBM MQ

java - H2 删除并创建别名 to_char 不起作用