List of usage examples for com.rabbitmq.client Channel queueDeclare
Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments) throws IOException;
From source file:com.grnet.parsers.Worker.java
License:Open Source License
@Override public void run() { // TODO Auto-generated method stub String name = xml.getName();//from w w w .j a v a2s. c o m Document document; try { SAXBuilder builder = new SAXBuilder(); document = (Document) builder.build(xml); Element rootNode = document.getRootElement(); Record record = new Record(); record.setMetadata(rootNode); String elementsString = properties.getProperty(Constants.elements); String[] elements = elementsString.split(","); for (int i = 0; i < elements.length; i++) { List<Element> elementList = JDomUtils.getXpathList(elements[i], Namespace.getNamespace(properties.getProperty(Constants.prefix), properties.getProperty(Constants.uri)), record.getMetadata()); if (elementList != null) { for (int j = 0; j < elementList.size(); j++) { Element elmt = elementList.get(j); String titleText = elmt.getText(); if (!titleText.equals("")) { Attribute langAtt = elmt.getAttribute(properties.getProperty(Constants.attName)); String chosenLangAtt = properties.getProperty(Constants.attName); if (langAtt == null || langAtt.getValue().equals("") || langAtt.getValue().equals("none")) { StringBuffer logstring = new StringBuffer(); try { Detector detector = DetectorFactory.create(); detector.append(titleText); String lang = detector.detect(); Attribute attribute = new Attribute(chosenLangAtt, lang); elmt.setAttribute(attribute); stats.raiseElementsLangDetected(); logstring.append(xml.getParentFile().getName()); logstring.append(" " + name.substring(0, name.lastIndexOf("."))); logstring.append(" " + elements[i]); logstring.append(" " + lang); slf4jLogger.info(logstring.toString()); System.out.println("Opening queue connection..."); Connection connection = this.factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(this.queue, false, false, false, null); channel.basicPublish("", this.queue, null, logstring.toString().getBytes()); channel.close(); connection.close(); System.out.println("Opening queue connection..."); stats.addElementD(elements[i]); flag = true; } catch (LangDetectException e) { // TODO Auto-generated catch block // e.printStackTrace(); logstring.append(xml.getParentFile().getName()); logstring.append(" " + name.substring(0, name.lastIndexOf("."))); logstring.append(" " + "NoLangDetected"); slf4jLogger.info(logstring.toString()); Connection connection = this.factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(this.queue, false, false, false, null); channel.basicPublish("", this.queue, null, logstring.toString().getBytes()); channel.close(); connection.close(); if (strict.equals("true")) recon = false; else { recon = true; continue; } } } } } } } if (recon) { String xmlString = JDomUtils.parseXml2string(record.getMetadata().getDocument(), null); OaiUtils.writeStringToFileInEncodingUTF8(xmlString, outputPath + File.separator + name); } else { String xmlString = JDomUtils.parseXml2string(record.getMetadata().getDocument(), null); OaiUtils.writeStringToFileInEncodingUTF8(xmlString, bad + File.separator + name); } if (flag) stats.raiseFilesLangDetected(); if (recon == false) stats.raiseFilessLangNotDetected(); } catch (JDOMException | IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:com.hopped.running.demo.RunServer.java
License:Open Source License
/** * /*from w w w . ja v a2 s.c o m*/ * @param args * @throws IOException */ public static void main(String[] args) throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); final String queueName = "runningRabbit"; Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.basicQos(1); channel.queueDeclare(queueName, false, false, false, null); ProtobufRPCServer server = new ProtobufRPCServer(channel, queueName).init() .setInstance(new RunnerServiceImpl()).setProtocol(IRunnerService.class); server.consume(); }
From source file:com.hpe.caf.util.rabbitmq.RabbitUtil.java
License:Apache License
/** * Declare a queue with arbitrary parameters and properties. * @param channel the channel to use to declare the queue * @param queueName the name of the queue * @param dur the durability setting of the queue * @param excl the exclusivity setting of the queue * @param act the empty action setting of the queue * @param queueProps the queue properties map * @throws IOException if the queue already exists AND the parameter settings do not match the existing queue * @since 2.0//from w w w .j a v a2 s .co m */ public static void declareQueue(Channel channel, String queueName, Durability dur, Exclusivity excl, EmptyAction act, Map<String, Object> queueProps) throws IOException { Objects.requireNonNull(queueName); Objects.requireNonNull(dur); Objects.requireNonNull(excl); Objects.requireNonNull(act); Objects.requireNonNull(queueProps); channel.queueDeclare(queueName, dur == Durability.DURABLE, excl == Exclusivity.EXCLUSIVE, act == EmptyAction.AUTO_REMOVE, queueProps); }
From source file:com.jbrisbin.vcloud.cache.RabbitMQAsyncCache.java
License:Apache License
@Override public void start() { active.set(true);/*from ww w . ja v a 2s . co m*/ try { Channel channel = getConnection().createChannel(); channel.exchangeDeclare(objectRequestExchange, "topic", true, false, null); channel.queueDeclare(id, true, false, true, null); } catch (IOException e) { log.error(e.getMessage(), e); } // For loading objects for (int i = 0; i < maxWorkers; i++) { activeTasks.add(workerPool.submit(new ObjectSender())); activeTasks.add(workerPool.submit(new CommandSender())); workerPool.submit(new Runnable() { @Override public void run() { try { Channel channel = getConnection().createChannel(); ObjectLoadMonitor loadMonitor = new ObjectLoadMonitor(channel); channel.basicConsume(id, loadMonitor); } catch (IOException e) { log.error(e.getMessage(), e); } } }); } activeTasks.add(workerPool.submit(new HeartbeatMonitor())); commandMessages.add(new CommandMessage("ping", heartbeatExchange, "")); delayTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { if (cacheNodes.size() > 0) { numOfCacheNodes.set(cacheNodes.size()); } } }, 0, heartbeatInterval); }
From source file:com.jbrisbin.vcloud.cache.RabbitMQAsyncCacheProvider.java
License:Apache License
@Override public void start() { active.set(true);//from w w w .j ava 2 s . co m try { Channel channel = getConnection().createChannel(); channel.exchangeDeclare(objectRequestExchange, "topic", true, false, null); channel.queueDeclare(cacheNodeQueueName, true, false, true, null); channel.queueBind(cacheNodeQueueName, objectRequestExchange, "#"); channel.exchangeDeclare(heartbeatExchange, "fanout", true, false, null); } catch (IOException e) { log.error(e.getMessage(), e); } activeTasks.add(workerPool.submit(new HeartbeatMonitor())); delayTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { commandMessages.add(new CommandMessage("ping", heartbeatExchange, "")); } }, 0, heartbeatInterval); delayTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { numOfPeers.set(peers.size()); if (debug) { log.debug("Expecting responses from " + numOfPeers.get() + " peers."); } } }, heartbeatInterval, heartbeatInterval); for (int i = 0; i < maxWorkers; i++) { activeTasks.add(workerPool.submit(new ObjectSender())); activeTasks.add(workerPool.submit(new CommandSender())); workerPool.submit(new Runnable() { @Override public void run() { try { Channel channel = getConnection().createChannel(); ObjectMonitor monitor = new ObjectMonitor(channel); channel.basicConsume(cacheNodeQueueName, monitor); } catch (IOException e) { log.error(e.getMessage(), e); } } }); } }
From source file:com.loanbroker.old.JSONReceiveTest.java
public static void main(String[] argv) throws IOException, InterruptedException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setUsername("student"); factory.setPassword("cph"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "fanout"); String queueName = "Kender du hende der Arne"; channel.queueDeclare(queueName, false, false, false, null); channel.queueBind(queueName, EXCHANGE_NAME, ""); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String messageIn = new String(delivery.getBody()); System.out.println(" [x] Received by tester: '" + messageIn + "'"); }/*from w ww . j a v a 2s . c o m*/ }
From source file:com.loanbroker.old.JSONSendTest.java
public static void main(String[] argv) throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setUsername("student"); factory.setPassword("cph"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "fanout"); String queueName = "Kender du hende der Arne"; channel.queueDeclare(queueName, false, false, false, null); channel.queueBind(queueName, EXCHANGE_NAME, ""); String messageOut = "{\"ssn\":1605789787,\"creditScore\":699,\"loanAmount\":10.0,\"loanDuration\":360}"; BasicProperties.Builder props = new BasicProperties().builder(); props.replyTo(""); BasicProperties bp = props.build();// w w w . jav a 2 s . c om channel.basicPublish(EXCHANGE_NAME, "", bp, messageOut.getBytes()); System.out.println(" [x] Sent by JSONtester: '" + messageOut + "'"); channel.close(); connection.close(); }
From source file:com.lumlate.midas.email.GmailReader.java
License:Apache License
/** * Authenticates to IMAP with parameters passed in on the commandline. *//*from www .java 2 s . c om*/ public static void main(String args[]) throws Exception { String mysqlhost = "localhost"; String mysqlport = "3306"; String mysqluser = "lumlate"; String mysqlpassword = "lumlate$"; String database = "lumlate"; MySQLAccess myaccess = new MySQLAccess(mysqlhost, mysqlport, mysqluser, mysqlpassword, database); String email = "sharmavipul@gmail.com"; String oauthToken = "1/co5CyT8QrJXyJagK5wzWNGZk2RTA0FU_dF9IhwPvlBs"; String oauthTokenSecret = "aK5LCYOFrUweFPfMcPYNXWzg"; String TASK_QUEUE_NAME = "gmail_oauth"; String rmqserver = "rmq01.deallr.com"; initialize(); IMAPSSLStore imapSslStore = connectToImap("imap.googlemail.com", 993, email, oauthToken, oauthTokenSecret, getDeallrConsumer(), true); ConnectionFactory factory = new ConnectionFactory(); factory.setHost(rmqserver); factory.setUsername("lumlate"); factory.setPassword("lumlate$"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); Folder folder = imapSslStore.getFolder("INBOX");//get inbox folder.open(Folder.READ_WRITE);//open folder only to read SearchTerm flagterm = new FlagTerm(new Flags(Flags.Flag.SEEN), false); RetailersDAO retaildao = new RetailersDAO(); retaildao.setStmt(myaccess.getConn().createStatement()); LinkedList<String> retaildomains = retaildao.getallRetailerDomains(); LinkedList<SearchTerm> searchterms = new LinkedList<SearchTerm>(); for (String retaildomain : retaildomains) { SearchTerm retailsearchterm = new FromStringTerm(retaildomain); searchterms.add(retailsearchterm); } SearchTerm[] starray = new SearchTerm[searchterms.size()]; searchterms.toArray(starray); SearchTerm st = new OrTerm(starray); //TODO add date to this as well so that fetch is since last time SearchTerm searchterm = new AndTerm(st, flagterm); Message message[] = folder.search(searchterm); for (int i = 0; i < message.length; i++) { Message msg = message[i]; ByteArrayOutputStream bos = new ByteArrayOutputStream(); msg.writeTo(bos); byte[] buf = bos.toByteArray(); channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, buf); } myaccess.Dissconnect(); channel.close(); connection.close(); }
From source file:com.lumlate.midas.email.InboxReader.java
License:Apache License
public Boolean readInbox(Properties props, String protocol, String hostname, String username, String password, Date lastfetch, String TASK_QUEUE_NAME) throws Exception { String rmqserver = props.getProperty("com.lumlate.midas.rmq.server"); String rmqusername = props.getProperty("com.lumlate.midas.rmq.username"); String rmqpassword = props.getProperty("com.lumlate.midas.rmq.password"); ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(rmqusername);/*from w w w . ja v a2s .c om*/ factory.setPassword(rmqpassword); factory.setHost(rmqserver); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); Session session = Session.getDefaultInstance(props, null); // session.setDebug(true); // session.setDebugOut(System.out); Store store = session.getStore(protocol); store.connect(hostname, username, password); // Folder folder = store.getFolder("Inbox");// get inbox Folder folder = store.getDefaultFolder(); folder.open(Folder.READ_WRITE); Folder deallrfolder = store.getFolder("Deallr"); // if (!deallrfolder.exists()) { try { deallrfolder.create(Folder.HOLDS_MESSAGES); } catch (Exception err) { System.out.println("Cannot create Folder"); err.printStackTrace(); } // } // SearchTerm flagterm = new FlagTerm(new Flags(Flags.Flag.SEEN), // false); SearchTerm[] starray = new SearchTerm[searchterms.size()]; searchterms.toArray(starray); SearchTerm st = new OrTerm(starray); // TODO add date to this as SearchTerm newerThen; // well so // that fetch is since last time if (lastfetch != null) { newerThen = new ReceivedDateTerm(ComparisonTerm.GT, lastfetch); // st = new AndTerm(st, flagterm); st = new AndTerm(st, newerThen); } else { newerThen = new ReceivedDateTerm(ComparisonTerm.GT, fetchsince); // st = new AndTerm(st, flagterm); st = new AndTerm(st, newerThen); } try { Message message[] = folder.search(st); for (int i = 0; i < message.length; i++) { Message msg = message[i]; folder.copyMessages(new Message[] { msg }, deallrfolder); msg.setFlag(Flag.SEEN, true); ByteArrayOutputStream bos = new ByteArrayOutputStream(); msg.writeTo(bos); byte[] buf = bos.toByteArray(); channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, buf); } } catch (Exception err) { err.printStackTrace(); throw new Exception(err.getMessage()); } folder.close(true); store.close(); channel.close(); connection.close(); return true; }
From source file:com.lumlate.midas.email.InboxReader.java
License:Apache License
public Boolean readOauthInbox(Properties props, String scope, String email, String oauthToken, String oauthTokenSecret, Date lastfetch, String TASK_QUEUE_NAME, String fetchtype) throws Exception { String rmqserver = props.getProperty("com.lumlate.midas.rmq.server"); String rmqusername = props.getProperty("com.lumlate.midas.rmq.username"); String rmqpassword = props.getProperty("com.lumlate.midas.rmq.password"); ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(rmqusername);/*from ww w .j av a2 s . com*/ factory.setPassword(rmqpassword); factory.setHost(rmqserver); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); Store imapSslStore = XoauthAuthenticator.connectToImap("imap.googlemail.com", 993, email, oauthToken, oauthTokenSecret, XoauthAuthenticator.getDeallrConsumer(), true); SearchTerm[] starray = new SearchTerm[searchterms.size()]; searchterms.toArray(starray); SearchTerm st = new OrTerm(starray); // TODO add date to this as SearchTerm newerThen; // that fetch is since last time if (lastfetch != null) { newerThen = new ReceivedDateTerm(ComparisonTerm.GT, lastfetch); st = new AndTerm(st, newerThen); } else { newerThen = new ReceivedDateTerm(ComparisonTerm.GT, fetchsince); st = new AndTerm(st, newerThen); } Folder folder = imapSslStore.getFolder("[Gmail]/All Mail");// get inbox folder.open(Folder.READ_WRITE); //Folder deallrfolder=null; //if(fetchtype.equalsIgnoreCase("scheduler")){ //deallrfolder = imapSslStore.getFolder("Deallr"); //if (!deallrfolder.exists()) // deallrfolder.create(Folder.HOLDS_MESSAGES); //} try { Message message[] = folder.search(st); for (int i = 0; i < message.length; i++) { Message msg = message[i]; msg.setFlag(Flag.SEEN, true); ByteArrayOutputStream bos = new ByteArrayOutputStream(); msg.writeTo(bos); byte[] buf = bos.toByteArray(); channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, buf); //if(deallrfolder!=null){ // folder.copyMessages(new Message[] { msg }, deallrfolder); //} } } catch (Exception err) { err.printStackTrace(); throw new Exception(err.getMessage()); } folder.close(true); //deallrfolder.close(true); imapSslStore.close(); channel.close(); connection.close(); return true; }