Example usage for com.rabbitmq.client MessageProperties PERSISTENT_TEXT_PLAIN

List of usage examples for com.rabbitmq.client MessageProperties PERSISTENT_TEXT_PLAIN

Introduction

In this page you can find the example usage for com.rabbitmq.client MessageProperties PERSISTENT_TEXT_PLAIN.

Prototype

BasicProperties PERSISTENT_TEXT_PLAIN

To view the source code for com.rabbitmq.client MessageProperties PERSISTENT_TEXT_PLAIN.

Click Source Link

Document

Content-type "text/plain", deliveryMode 2 (persistent), priority zero

Usage

From source file:edu.indiana.d2i.sead.matchmaker.service.messaging.Sender.java

License:Apache License

public void sendMessage(File messageFile) throws IOException, ShutdownSignalException, InterruptedException {
    InputStream is = new FileInputStream(messageFile);

    // Get the size of the file
    long length = messageFile.length();
    if (length > Integer.MAX_VALUE) {
        throw new IOException("Input File (" + messageFile.getName() + ") is to large! ");
    }/*from   ww  w .  j  av a2  s.  c  om*/
    byte[] messageBodyBytes = new byte[(int) length];
    int offset = 0;
    int numRead = 0;
    while (offset < messageBodyBytes.length
            && (numRead = is.read(messageBodyBytes, offset, messageBodyBytes.length - offset)) >= 0) {
        offset += numRead;
    }
    if (offset < messageBodyBytes.length) {
        throw new IOException("Could not completely read file " + messageFile.getName());
    }
    is.close();
    this.channel.basicPublish(this.ExchangeName, this.RoutingKey, MessageProperties.PERSISTENT_TEXT_PLAIN,
            messageBodyBytes);

}

From source file:edu.iu.messaging.service.core.impl.RabbitMQPublisher.java

License:Apache License

public void send(byte[] message, String routingKey) throws Exception {
    try {/*  w  w  w  .ja  v a  2  s .co m*/
        channel.basicPublish(properties.getExchangeName(), routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN,
                message);
    } catch (IOException e) {
        logger.error("send() -> Error sending message.", e);
    }
}

From source file:edu.jhu.pha.vospace.node.DataNode.java

License:Apache License

/**
 * Set the node content/*from   w  ww . j  a  v a  2s .  c  o  m*/
 * @param data The new node content
 */
public void setData(InputStream data) {
    if (!getMetastore().isStored(getUri()))
        throw new NotFoundException("NodeNotFound");
    logger.debug("Updating node " + getUri().toString());

    // put the node data into storage
    getStorage().putBytes(getUri().getNodePath(), data);

    // update node size from storage to metadata
    getStorage().updateNodeInfo(getUri().getNodePath(), getNodeInfo());

    getNodeInfo().setRevision(getNodeInfo().getRevision() + 1);//increase revision version to store in DB

    getMetastore().storeInfo(getUri(), getNodeInfo());

    QueueConnector.goAMQP("setData", new QueueConnector.AMQPWorker<Boolean>() {
        @Override
        public Boolean go(com.rabbitmq.client.Connection conn, com.rabbitmq.client.Channel channel)
                throws IOException {

            channel.exchangeDeclare(conf.getString("vospace.exchange.nodechanged"), "fanout", false);
            channel.exchangeDeclare(conf.getString("process.exchange.nodeprocess"), "fanout", true);

            Map<String, Object> nodeData = new HashMap<String, Object>();
            nodeData.put("uri", getUri().toString());
            nodeData.put("owner", getOwner());
            nodeData.put("container", getUri().getNodePath().getParentPath().getNodeStoragePath());

            byte[] jobSer = (new ObjectMapper()).writeValueAsBytes(nodeData);
            channel.basicPublish(conf.getString("vospace.exchange.nodechanged"), "", null, jobSer);
            channel.basicPublish(conf.getString("process.exchange.nodeprocess"), "",
                    MessageProperties.PERSISTENT_TEXT_PLAIN, jobSer);

            return true;
        }
    });

}

From source file:edu.jhu.pha.vospace.node.DataNode.java

License:Apache License

public void setChunkedData(String uploadId) {
    if (!getMetastore().isStored(getUri()))
        throw new NotFoundException("NodeNotFound");
    logger.debug("Updating chunked node " + getUri().toString());

    VoSyncMetaStore vosyncMeta = new VoSyncMetaStore(this.owner);

    // put the node data into storage
    getStorage().putChunkedBytes(getUri().getNodePath(), uploadId);

    vosyncMeta.deleteNodeChunks(this.getUri());
    vosyncMeta.mapChunkedToNode(this.getUri(), uploadId);

    // update node size from storage to metadata
    getStorage().updateNodeInfo(getUri().getNodePath(), getNodeInfo());

    getNodeInfo().setRevision(getNodeInfo().getRevision() + 1);//increase revision version to store in DB

    getMetastore().storeInfo(getUri(), getNodeInfo());

    QueueConnector.goAMQP("setData", new QueueConnector.AMQPWorker<Boolean>() {
        @Override//from  w w w  . j  a  va  2  s.  c o m
        public Boolean go(com.rabbitmq.client.Connection conn, com.rabbitmq.client.Channel channel)
                throws IOException {

            channel.exchangeDeclare(conf.getString("vospace.exchange.nodechanged"), "fanout", false);
            channel.exchangeDeclare(conf.getString("process.exchange.nodeprocess"), "fanout", true);

            Map<String, Object> nodeData = new HashMap<String, Object>();
            nodeData.put("uri", getUri().toString());
            nodeData.put("owner", getOwner());
            nodeData.put("container", getUri().getNodePath().getParentPath().getNodeStoragePath());

            byte[] jobSer = (new ObjectMapper()).writeValueAsBytes(nodeData);
            channel.basicPublish(conf.getString("vospace.exchange.nodechanged"), "", null, jobSer);
            channel.basicPublish(conf.getString("process.exchange.nodeprocess"), "",
                    MessageProperties.PERSISTENT_TEXT_PLAIN, jobSer);

            return true;
        }
    });

}

From source file:edu.jhu.pha.vospace.node.Node.java

License:Apache License

public void copy(VospaceId newLocationId, final boolean keepBytes) {
    if (!isStoredMetadata())
        throw new NotFoundException("NodeNotFound");

    if (getMetastore().isStored(newLocationId))
        throw new ForbiddenException("DestinationNodeExists");

    getStorage().copyBytes(getUri().getNodePath(), newLocationId.getNodePath(), keepBytes);

    if (!keepBytes) {
        // update node's container size metadata
        try {//www .j  a va 2s.com
            ContainerNode contNode = (ContainerNode) NodeFactory.getNode(
                    new VospaceId(new NodePath(getUri().getNodePath().getContainerName())), getOwner());
            getStorage().updateNodeInfo(contNode.getUri().getNodePath(), contNode.getNodeInfo());
            getMetastore().storeInfo(contNode.getUri(), contNode.getNodeInfo());
        } catch (URISyntaxException e) {
            logger.error("Updating root node size failed: " + e.getMessage());
        }
    }

    final Node newDataNode = NodeFactory.createNode(newLocationId, owner, this.getType());
    newDataNode.setNode(null);
    newDataNode.getStorage().updateNodeInfo(newLocationId.getNodePath(), newDataNode.getNodeInfo());
    newDataNode.getMetastore().storeInfo(newLocationId, newDataNode.getNodeInfo());
    newDataNode.getMetastore().updateUserProperties(newLocationId, getNodeMeta(PropertyType.property));

    // Update chunks table to point to the new node if the node is chunked
    // copy with keepBytes=true is prohibited for chunked files by swift storage
    if (null != this.getNodeInfo().getChunkedName()) {
        VoSyncMetaStore vosyncMeta = new VoSyncMetaStore(this.owner);
        vosyncMeta.mapChunkedToNode(newDataNode.getUri(), this.getNodeInfo().getChunkedName());
    }

    if (!keepBytes)
        newDataNode.getMetastore().remove(this.getUri());

    QueueConnector.goAMQP("copyNode", new QueueConnector.AMQPWorker<Boolean>() {
        @Override
        public Boolean go(com.rabbitmq.client.Connection conn, com.rabbitmq.client.Channel channel)
                throws IOException {

            channel.exchangeDeclare(conf.getString("vospace.exchange.nodechanged"), "fanout", false);
            channel.exchangeDeclare(conf.getString("process.exchange.nodeprocess"), "fanout", true);

            Map<String, Object> nodeData = new HashMap<String, Object>();
            nodeData.put("uri", newDataNode.getUri().toString());
            nodeData.put("owner", getOwner());
            nodeData.put("container", newDataNode.getUri().getNodePath().getParentPath().getNodeStoragePath());

            byte[] jobSer = (new ObjectMapper()).writeValueAsBytes(nodeData);
            channel.basicPublish(conf.getString("vospace.exchange.nodechanged"), "", null, jobSer);
            channel.basicPublish(conf.getString("process.exchange.nodeprocess"), "",
                    MessageProperties.PERSISTENT_TEXT_PLAIN, jobSer);

            if (!keepBytes) {
                Map<String, Object> oldNodeData = new HashMap<String, Object>();
                oldNodeData.put("uri", getUri().toString());
                oldNodeData.put("owner", getOwner());
                oldNodeData.put("container", getUri().getNodePath().getParentPath().getNodeStoragePath());

                byte[] oldNodejobSer = (new ObjectMapper()).writeValueAsBytes(oldNodeData);
                channel.basicPublish(conf.getString("vospace.exchange.nodechanged"), "", null, oldNodejobSer);
            }
            return true;
        }
    });
}

From source file:es.devcircus.rabbitmq_examples.rabbitmq_work_queues.NewTask.java

License:Open Source License

/**
 * /*w ww . ja va 2  s  .com*/
 * @param argv
 * @throws Exception 
 */
public static void main(String[] argv) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);

    String message = getMessage(argv);

    channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
    System.out.println(" [x] Sent '" + message + "'");

    channel.close();
    connection.close();
}

From source file:hudson.plugins.collabnet.orchestrate.AmqpOrchestrateClient.java

License:Apache License

/**
 * Creates an EventQ MQ client with default settings
 *//*from w ww . j a v  a 2  s.c om*/
public AmqpOrchestrateClient() {
    this.exchangeName = DEFAULT_EXCHANGE_NAME; // the default exchange
    this.routingKey = DEFAULT_QUEUE_NAME; // the routing key / queue name
    this.properties = MessageProperties.PERSISTENT_TEXT_PLAIN; // the message type (durable)
}

From source file:hudson.plugins.collabnet.orchestrate.TestAmqpOrchestrateClient.java

License:Apache License

/** Validate the message durability setting */
@Test//from w w w .  ja  v  a 2 s .  co  m
public void persistentMessageTypeIsUsed() {
    AMQP.BasicProperties persistentMessageType = MessageProperties.PERSISTENT_TEXT_PLAIN;
    TestCase.assertEquals("The persistent message type should be used", persistentMessageType,
            orchestrateClient.getProperties());
}

From source file:info.pancancer.arch3.jobGenerator.JobGenerator.java

License:Open Source License

private void enqueueNewJobs(String job) {

    try {//w w w.  j  av a  2  s .com
        log.info("\nSENDING JOB:\n '" + job + "'\n" + this.jchannel + " \n");

        this.jchannel.basicPublish("", queueName + "_orders", MessageProperties.PERSISTENT_TEXT_PLAIN,
                job.getBytes(StandardCharsets.UTF_8));
        jchannel.waitForConfirms();
    } catch (IOException | InterruptedException ex) {
        log.error(ex.toString());
    }

}

From source file:info.pancancer.arch3.worker.WorkerHeartbeat.java

License:Open Source License

@Override
public void run() {

    Channel reportingChannel = null;
    try {/*from   w ww  .j  a  va  2  s.  c  o m*/
        try {
            reportingChannel = Utilities.setupExchange(settings, this.queueName);
        } catch (IOException | TimeoutException | AlreadyClosedException e) {
            LOG.error("Exception caught! Queue channel could not be opened, waiting. Exception is: "
                    + e.getMessage(), e);
            // retry after a minute, do not die simply because the launcher is unavailable, it may come back
            Thread.sleep(Base.ONE_MINUTE_IN_MILLISECONDS);
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        LOG.info("Caught interrupt signal, heartbeat shutting down.", e);
        return;
    }

    LOG.info("starting heartbeat thread, will send heartbeat message ever " + secondsDelay + " seconds.");
    while (!Thread.interrupted()) {
        // byte[] stdOut = this.getMessageBody().getBytes(StandardCharsets.UTF_8);
        try {
            try {
                Status heartbeatStatus = new Status();
                heartbeatStatus.setJobUuid(this.jobUuid);
                heartbeatStatus.setMessage("job is running; IP address: " + networkID);
                heartbeatStatus.setState(StatusState.RUNNING);
                heartbeatStatus.setType(Utilities.JOB_MESSAGE_TYPE);
                heartbeatStatus.setVmUuid(this.vmUuid);
                heartbeatStatus.setIpAddress(networkID);

                // String stdOut = this.statusSource.getStdOut();
                Lock lock = new ReentrantLock();
                lock.lock();
                String stdOut = this.statusSource.getStdOut(stdoutSnipSize);
                String stdErr = this.statusSource.getStdErr();
                lock.unlock();
                heartbeatStatus.setStdout(stdOut);
                heartbeatStatus.setStderr(stdErr);
                String heartBeatMessage = heartbeatStatus.toJSON();
                LOG.debug("Sending heartbeat message to " + queueName + ", with body: " + heartBeatMessage);
                reportingChannel.basicPublish(queueName, queueName, MessageProperties.PERSISTENT_TEXT_PLAIN,
                        heartBeatMessage.getBytes(StandardCharsets.UTF_8));
                reportingChannel.waitForConfirms();

                Thread.sleep((long) (secondsDelay * MILLISECONDS_PER_SECOND));
            } catch (IOException | AlreadyClosedException e) {
                LOG.error("IOException caught! Message may not have been published. Exception is: "
                        + e.getMessage(), e);
                // retry after a minute, do not die simply because the launcher is unavailable, it may come back
                Thread.sleep(Base.ONE_MINUTE_IN_MILLISECONDS);
            }
        } catch (InterruptedException e) {
            LOG.info("Heartbeat shutting down.");
            if (reportingChannel.getConnection().isOpen()) {
                try {
                    reportingChannel.getConnection().close();
                } catch (IOException e1) {
                    LOG.error("Error closing reportingChannel connection: " + e1.getMessage(), e1);
                }
            }
            if (reportingChannel.isOpen()) {
                try {
                    reportingChannel.close();
                } catch (IOException e1) {
                    LOG.error("Error (IOException) closing reportingChannel: " + e1.getMessage(), e1);
                } catch (TimeoutException e1) {
                    LOG.error("Error (TimeoutException) closing reportingChannel: " + e1.getMessage(), e1);
                }
            }
            LOG.debug("reporting channel open: " + reportingChannel.isOpen());
            LOG.debug("reporting channel connection open: " + reportingChannel.getConnection().isOpen());

            Thread.currentThread().interrupt();
        }
    }
}