Simples Assim

How to Create a Command for CRaSH

leave a comment »

1) Create the command class:

import org.crsh.cli.Named

class sample {

  @Command
  @Named("do-something")
  @Usage("Does something")
  Object doSomething() {
    return null
  }

}

2) Drop the command class in the <CRaSH Install Dir>/cmd folder.

3) Run the command:

% sample do-something

Written by Fernando Ribeiro

March 29, 2015 at 12:18 am

Posted in Software

Tagged with , ,

How to Receive a Message from an Apache ActiveMQ Topic with OCaml

leave a comment »

W/o Durability

open Unix

let in_channel, out_channel = open_connection (ADDR_INET (inet_addr_of_string "127.0.0.1", 61613))

output_string out_channel "CONNECT\n\n\000"

flush out_channel

let line = ref (input_line in_channel)

while !line <> "\000" do
  line := input_line in_channel
done

output_string out_channel "SUBSCRIBE\ndestination:/topic/SampleTopic\n\nack:auto\n\n\000"

flush out_channel

let line = ref (input_line in_channel)

while !line <> "" do
  line := input_line in_channel
done

print_string (input_line in_channel)

output_string out_channel "DISCONNECT\n\n\000"

shutdown_connection in_channel

close_out out_channel

W/ Durability

open Unix

let in_channel, out_channel = open_connection (ADDR_INET (inet_addr_of_string "127.0.0.1", 61613))

output_string out_channel "CONNECT\nclient-id:SampleClient\n\n\000"

flush out_channel

let line = ref (input_line in_channel)

while !line <> "\000" do
  line := input_line in_channel
done

output_string out_channel "SUBSCRIBE\ndestination:/topic/SampleTopic\nack:auto\nactivemq.subscriptionName:SampleSubscription\n\n\000"

flush out_channel

let line = ref (input_line in_channel)

while !line <> "" do
  line := input_line in_channel
done

print_string (input_line in_channel)

output_string out_channel "DISCONNECT\n\n\000"

shutdown_connection in_channel

close_out out_channel

Written by Fernando Ribeiro

February 22, 2015 at 7:04 pm

How to Receive a Message from an Apache ActiveMQ Queue with OCaml

leave a comment »

open Unix

let in_channel, out_channel = open_connection (ADDR_INET (inet_addr_of_string "127.0.0.1", 61613))

output_string out_channel "CONNECT\n\n\000"

flush out_channel

let line = ref (input_line in_channel)

while !line <> "\000" do
  line := input_line in_channel
done

output_string out_channel "SUBSCRIBE\ndestination:SampleQueue\n\nack:auto\n\n\000"

flush out_channel

let line = ref (input_line in_channel)

while !line <> "" do
  line := input_line in_channel
done

print_string (input_line in_channel)

output_string out_channel "DISCONNECT\n\n\000"

shutdown_connection in_channel

close_out out_channel

Written by Fernando Ribeiro

February 22, 2015 at 7:03 pm

How to Send a Message to an Apache ActiveMQ Topic with OCaml

leave a comment »

open Unix

let _, out_channel = open_connection (ADDR_INET (inet_addr_of_string "127.0.0.1", 61613))

output_string out_channel "CONNECT\n\n\000"

output_string out_channel "SEND\ndestination:/topic/SampleTopic\n\nSimples Assim\000"

output_string out_channel "DISCONNECT\n\n\000"

close_out out_channel

Written by Fernando Ribeiro

February 22, 2015 at 7:03 pm

How to Send a Message to an Apache ActiveMQ Queue with OCaml

leave a comment »

open Unix

let _, out_channel = open_connection (ADDR_INET (inet_addr_of_string "127.0.0.1", 61613))

output_string out_channel "CONNECT\n\n\000"

output_string out_channel "SEND\ndestination:SampleQueue\n\nSimples Assim\000"

output_string out_channel "DISCONNECT\n\n\000"

close_out out_channel

Written by Fernando Ribeiro

February 21, 2015 at 9:34 pm

How to Receive a Message from an Apache ActiveMQ Topic with OCaml-Java

leave a comment »

W/o Durability

open Java

open JavaString

open Package'java'io

open Package'javax'jms

open Package'org'apache'activemq

let conn_factory = Java.make "ActiveMQConnectionFactory()" ()

let conn = call "ConnectionFactory.createConnection()" conn_factory

let sess = call "Connection.createSession(boolean, int)" conn false (get "Session.AUTO_ACKNOWLEDGE" ())

let dest = call "Session.createTopic(String)" sess (of_string "SampleTopic")

let cons = call "Session.createConsumer(Destination)" sess dest

let _ = call "Connection.start()" conn

let msg = call "MessageConsumer.receive()" cons

let _ = call "PrintStream.println(Object)" (get "System.out" ()) msg

let _ = call "Connection.close()" conn

W/ Durability

open Java

open JavaString

open Package'java'io

open Package'javax'jms

open Package'org'apache'activemq

let conn_factory = Java.make "ActiveMQConnectionFactory()" ()

let conn = call "ConnectionFactory.createConnection()" conn_factory

let _ = call "Connection.setClientID(String)" conn (of_string "SampleClient")

let sess = call "Connection.createSession(boolean, int)" conn false (get "Session.AUTO_ACKNOWLEDGE" ())

let dest = call "Session.createTopic(String)" sess (of_string "SampleTopic")

let cons = call "Session.createDurableSubscriber(Topic, String)" sess dest (of_string "SampleSubscription")

let _ = call "Connection.start()" conn

let msg = call "MessageConsumer.receive()" cons

let _ = call "PrintStream.println(Object)" (get "System.out" ()) msg

let _ = call "Connection.close()" conn

Written by Fernando Ribeiro

February 15, 2015 at 11:22 pm

How to Receive a Message from an Apache ActiveMQ Queue with OCaml-Java

leave a comment »

open Java

open JavaString

open Package'java'io

open Package'javax'jms

open Package'org'apache'activemq

let conn_factory = Java.make "ActiveMQConnectionFactory()" ()

let conn = call "ConnectionFactory.createConnection()" conn_factory

let sess = call "Connection.createSession(boolean, int)" conn false (get "Session.AUTO_ACKNOWLEDGE" ())

let dest = call "Session.createQueue(String)" sess (of_string "SampleQueue")

let cons = call "Session.createConsumer(Destination)" sess dest

let _ = call "Connection.start()" conn

let msg = call "MessageConsumer.receive()" cons

let _ = call "PrintStream.println(Object)" (get "System.out" ()) msg

let _ = call "Connection.close()" conn

Written by Fernando Ribeiro

February 15, 2015 at 11:21 pm

Follow

Get every new post delivered to your Inbox.

Join 1,266 other followers