Example usage for javax.jms Session createObjectMessage

List of usage examples for javax.jms Session createObjectMessage

Introduction

In this page you can find the example usage for javax.jms Session createObjectMessage.

Prototype


ObjectMessage createObjectMessage(Serializable object) throws JMSException;

Source Link

Document

Creates an initialized ObjectMessage object.

Usage

From source file:org.openbaton.common.vnfm_sdk.amqp.VnfmSpringHelper.java

public MessageCreator getObjectMessageCreator(final Serializable message) {
    MessageCreator messageCreator = new MessageCreator() {
        @Override// w  w w.  j a va2s  .  c om
        public Message createMessage(Session session) throws JMSException {
            ObjectMessage objectMessage = session.createObjectMessage(message);
            return objectMessage;
        }
    };
    return messageCreator;
}

From source file:midas.service.CustomerDuplicatesService.java

@Transactional
public CustomerDuplicatesIndex indexDuplicates(final Boolean sync) {
    final int count = (int) customerJpaRepo.count();
    final int numPages = (count / INDEX_PAGE_SIZE) + 1;

    for (int page = 0; page < numPages; page++) {
        final CustomerDuplicatesIndexingPage indexPage = new CustomerDuplicatesIndexingPage(page, numPages,
                INDEX_PAGE_SIZE);/*  w w w  . j  a va  2 s.c o m*/
        if (Boolean.TRUE.equals(sync)) {
            indexDuplicates(indexPage);
        } else {
            jmsTemplate.send(INDEX_QUEUE_NAME, new MessageCreator() {
                public Message createMessage(Session session) throws JMSException {
                    return session.createObjectMessage(indexPage);
                }
            });
        }
    }

    return new CustomerDuplicatesIndex(numPages, INDEX_PAGE_SIZE,
            Boolean.TRUE.equals(sync) ? IndexStatus.FINISHED : IndexStatus.EXECUTING);
}

From source file:terrastore.event.impl.ActiveMQEventBus.java

private void enqueue(final Event event) {
    String queueName = TERRASTORE_QUEUE_PREFIX + event.getBucket();
    producer.send(queueName, new MessageCreator() {

        @Override/*w  ww  .j  a  v a 2 s.  co m*/
        public Message createMessage(Session session) throws JMSException {
            Message message = session.createObjectMessage(event);
            message.setStringProperty("JMSXGroupID", new StringBuilder().append(event.getBucket()).append(":")
                    .append(event.getKey()).toString());
            return message;
        }

    });
}

From source file:org.logicblaze.lingo.jms.marshall.DefaultMarshaller.java

public Message createResponseMessage(Session session, RemoteInvocationResult result, Message requestMessage)
        throws JMSException {
    ObjectMessage answer = session.createObjectMessage(result);
    addResponseMessageHeaders(answer, result, requestMessage);
    return answer;
}

From source file:com.orange.mmp.message.jms.JMSMessageDecorator.java

/**
 * Called to build a JMS Message from a MMP Message by JMSTemplate
 *//*from  www  . j a  v  a  2s. c  om*/
public javax.jms.Message createMessage(Session session) throws JMSException {
    //Create a new ObjectMessage in JMS
    if (message != null)
        this.jmsMessage = session.createObjectMessage(message);

    //Set the sender ID for loop routing issues
    this.jmsMessage.setStringProperty(MESSAGE_SELECTOR_SENDER_PROPERTY, this.instanceId);

    //Set replyTo field if must reply
    this.jmsMessage.setJMSReplyTo(this.replyTo);

    return this.jmsMessage;
}

From source file:de.elomagic.carafile.server.bl.SeedBean.java

public MetaData seedFile(final InputStream inputStream, final String filename)
        throws IOException, GeneralSecurityException, JMSException {
    LOG.debug("Seeding file " + filename);
    MetaData md;/*from  ww w  .  j a  v  a2 s .co  m*/
    md = new MetaData();
    md.setFilename(filename);
    md.setCreationDate(new Date());
    md.setChunkSize(DEFAULT_PIECE_SIZE);
    md.setRegistryURI(UriBuilder.fromUri(registryURI).build());

    MessageDigest messageDigest = DigestUtils.getSha1Digest();
    long totalBytes = 0;

    try (DigestInputStream dis = new DigestInputStream(inputStream, messageDigest)) {
        byte[] buffer = new byte[md.getChunkSize()];
        int bytesRead;
        while ((bytesRead = readBlock(dis, buffer)) > 0) {
            totalBytes += bytesRead;
            String chunkId = Hex
                    .encodeHexString(DigestUtils.sha1(new ByteArrayInputStream(buffer, 0, bytesRead)));

            repositoryBean.writeChunk(chunkId, buffer, bytesRead);

            URI uri = UriBuilder.fromUri(ownURI).build();

            ChunkData chunkData = new ChunkData(chunkId, uri);
            md.addChunk(chunkData);
        }
    }

    md.setSize(totalBytes);
    md.setId(Hex.encodeHexString(messageDigest.digest()));

    LOG.debug("File id of seed file is " + md.getId() + "; Size=" + md.getSize() + "; Chunks="
            + md.getChunks().size());

    // Initiate to register at tracker
    LOG.debug("Queue up new file for registration.");
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer messageProducer = session.createProducer(fileQueue);

    ObjectMessage message = session.createObjectMessage(md);

    messageProducer.send(message);

    connection.close();

    return md;
}

From source file:org.logicblaze.lingo.jms.marshall.DefaultMarshaller.java

public Message createObjectMessage(Session session, Object value) throws JMSException {
    Message message = null;// w ww  .j a v  a2  s.com
    if (value instanceof String) {
        message = session.createTextMessage((String) value);
    } else {
        message = session.createObjectMessage((Serializable) value);
    }
    appendMessageHeaders(message, session, value);
    return message;
}

From source file:com.fusesource.forge.jmstest.benchmark.command.transport.JMSCommandTransport.java

public void sendCommand(BenchmarkCommand command) {
    log.debug("Sending command message: " + command.toString());
    if (getConnection() != null) {
        try {/*from   w  ww. j  a  v  a  2 s.c  o m*/
            Session session = getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
            Destination dest = getJmsDestinationProvider().getDestination(session, getDestinationName());
            MessageProducer producer = session.createProducer(dest);
            producer.send(session.createObjectMessage((Serializable) command));
            session.close();
        } catch (Exception je) {
            log().error("Could not send Command " + command.toString() + ".", je);
        }
    } else {
        log.warn("Command not sent as JMS connection is not established.");
    }
}

From source file:com.chinamobile.bcbsp.comm.ProducerTool.java

/**
 * Send message into messageQueue and update information.
 * @param session/*  w ww  . j  a va2s  .  c  o  m*/
 * @param producer
 * @throws Exception
 *         e
 */
private void sendLoop(final Session session, final MessageProducer producer) throws Exception {
    IMessage msg;
    int count = 0;
    BSPMessagesPack pack = new BSPMessagesPack();
    ArrayList<IMessage> content = new ArrayList<IMessage>();
    while ((msg = messageQueue.poll()) != null) {
        content.add(msg);
        count++;
        this.messageCount++;
        // enough for a pack.
        if (count == this.packSize) {
            pack.setPack(content);
            long start = System.currentTimeMillis();
            /** Clock */
            ObjectMessage message = session.createObjectMessage(pack);
            producer.send(message);
            this.sendTime += (System.currentTimeMillis() - start);
            /** Clock */
            content.clear();
            count = 0;
        }
    }
    // remaining messages into a pack.
    if (content.size() > 0) {
        pack.setPack(content);
        long start = System.currentTimeMillis();
        /* Clock */
        ObjectMessage message = session.createObjectMessage(pack);
        producer.send(message);
        this.sendTime += (System.currentTimeMillis() - start);
        /* Clock */
        content.clear();
    }
}