Как написать код java для передачи файла в IBM MQ с сохранением имени файла - PullRequest
0 голосов
/ 17 июня 2020

Я пытаюсь написать сценарий на 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();

Но вместо содержимого String я хочу отправить файл так же, как это делает 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.

Диаграмма классов для imqsput

1 Ответ

0 голосов
/ 19 июня 2020

DOgl, если я правильно понял, вы хотите отправить файл в виде сообщения в очередь или может быть наоборот. Так вы пробовали использовать управляемую передачу файлов MQ в комплекте с IBM MQ? Он широко известен как IBM MQ MFT. У этого будет решение для вашего сценария.

...