Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ out
build-local.properties
.gradle
build
gradle
gradlew
gradlew.bat

# Github java basic
*.class
Expand Down
21 changes: 21 additions & 0 deletions j2se/java-amqp-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This J2SE console app communicates over WebSocket with an AMQP server via Kaazin

## Steps for Building and Running the Project

- Install gradle: follow the steps [here](https://gradle.org/gradle-download/).

- Build the application using gradle

```bash
Expand All @@ -25,6 +27,25 @@ or
```
build\install\java-amqp-demo\bin\java-amqp-demo.bat
```

**NOTE:** The application can be run in the folowing ways:
- To connect to our default URI and default credentials (guest/guest):
```
/java-amqp-demo
```
- To connect to your own local Kaazing Gateway URI (ex: *ws://localhost:8000/zmqp*):
```
/java-jms-demo '{YOUR.GATEWAY.URI}'
```
- To use credentials with our default URI:
```
/java-aqmp-demo 'guest' 'guest'
```
- If you have setup your gateway for authentification:
```
/java-jms-demo '{YOUR.GATEWAY.URI}' '{USERNAME}' '{PASSWORD}'
```

**Note:** If you encounter an exception, try running the program as the root user (`sudo`).

## Interact with Kaazing Java AMQP Client API
Expand Down
2 changes: 1 addition & 1 deletion j2se/java-amqp-demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'eclipse'
apply plugin: 'application'

sourceCompatibility = 1.8
mainClassName = 'com.kaazing.amqp.client.demo.JavaAmqpClientDemo'
mainClassName = 'com.kaazing.amqp.client.demo.AmqpDemoClientMain'


repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.kaazing.amqp.client.demo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;

public class AmqpDemoClientMain {
public static void main(String[] args) throws InterruptedException, URISyntaxException, IOException {
JavaAmqpClientDemo demo = null;
switch (args.length){
case 0:
demo = new JavaAmqpClientDemo("ws://sandbox.kaazing.net/amqp091", "guest", "guest");
break;
case 1:
demo = new JavaAmqpClientDemo(args[0], "guest", "guest");
break;
case 2:
demo = new JavaAmqpClientDemo("ws://sandbox.kaazing.net/jms", args[0], args[1]);
break;
case 3:
demo = new JavaAmqpClientDemo(args[0], args[1], args[2]);
break;
default:
System.out.println("Possible usage of the Kaazing Java JMS Demo: \n" +
" 1. If you want to connect to our default URI and default credentials (guest/guest): \n" +
" /java-amqp-demo\n" +
" 2. If you want to connect to your own local Kaazing Gateway URI (ex: *ws://localhost:8000/jms*):\n" +
" /java-amqp-demo '{YOUR.GATEWAY.URI}' \n" +
" 3. If you want to use authentication with our default URI: \n" +
" /java-aqmp-demo 'username' `password` \n" +
" 4. If you have setup your gateway for authentication: \n" +
" /java-amqp-demo '{YOUR.GATEWAY.URI}' '{USERNAME}' '{PASSWORD}' \n" +
"Please restart your the Kaazing Java AMQP Demo and input the correct parameters as stated above!");
System.exit(1);
}
demo.handleConnection();
System.out.println("Kaazing Java AMQP Demo App. Copyright (C) 2017 Kaazing, Inc.");
System.out.println("Type the message to send or <exit> to stop.");
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String text = console.readLine();
if (text.equalsIgnoreCase("<exit>"))
break;
// Send as a text
demo.sendMessage(text);
}
demo.disconnect();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.kaazing.net.ws.amqp.ConnectionEvent;
import com.kaazing.net.ws.amqp.ConnectionListener;

import javax.net.ssl.SSLHandshakeException;

public class JavaAmqpClientDemo {
private AmqpClient amqpClient;
private AmqpChannel publishChannel = null;
Expand All @@ -31,10 +33,19 @@ public class JavaAmqpClientDemo {
private final String myConsumerTag = "clientkey";
private final String routingKey = "broadcastkey";
private final String virtualHost = "/";
private String login;
private final String url;
private final String login;
private final String password;


public JavaAmqpClientDemo(URI url, String login, String password) throws InterruptedException {
public JavaAmqpClientDemo(String url, String login, String password) throws InterruptedException {
this.url = url;
this.login = login;
this.password = password;
}

public void handleConnection() throws InterruptedException {

AmqpClientFactory amqpClientFactory = AmqpClientFactory.createAmqpClientFactory();
amqpClient = amqpClientFactory.createAmqpClient();
System.out.println("CONNECTING: " + url + " " + login + "/" + password);
Expand Down Expand Up @@ -62,6 +73,7 @@ public void onConnectionClose(ConnectionEvent e) {
if (consumeChannel != null) {
consumeChannel.closeChannel(0, "", 0, 0);
}
System.exit(0);

}

Expand All @@ -70,7 +82,7 @@ public void onConnectionError(ConnectionEvent e) {
System.exit(-1);
}
});
amqpClient.connect(url.toString(), virtualHost, login, password);
amqpClient.connect(url, virtualHost, login, password);
connectionLatch.await(10, TimeUnit.SECONDS);

final CountDownLatch pubChannelLatch = new CountDownLatch(1);
Expand Down Expand Up @@ -119,7 +131,8 @@ public void onClose(ChannelEvent e) {

@Override
public void onConsumeBasic(ChannelEvent e) {
System.out.println("CONSUME FROM QUEUE: " + queueName);
System.out.println("CONSUME FROM QUEUE: " + queueName +"\n");
System.out.print("User input: ");
}

@Override
Expand All @@ -141,15 +154,15 @@ public void onMessage(final ChannelEvent e) {
final Long dt = (Long) e.getArgument("deliveryTag");
final String value = new String(bytes, Charset.forName("UTF-8"));

System.out.println(">>> MESSAGE RECEIVED: " + value);
System.out.println("<- MESSAGE RECEIVED: " + value);
AmqpProperties props = e.getAmqpProperties();
if (props != null) {
AmqpArguments headers = props.getHeaders();

System.out.println("Amqp properties: ");
if (headers != null) {
System.out.println("Headers: " + headers.toString());
System.out.println("- Headers: " + headers.toString());
}
System.out.println("Properties " + (String) props.toString());
System.out.println("- Properties " + (String) props.toString());

// Acknowledge the message as we passed in a 'false' for
// noAck in AmqpChannel.consumeBasic() call. If the
Expand All @@ -160,6 +173,7 @@ public void onMessage(final ChannelEvent e) {
AmqpChannel channel = e.getChannel();
channel.ackBasic(dt.longValue(), true);
}
System.out.print("\nUser input: ");
}

@Override
Expand All @@ -177,6 +191,11 @@ public void disconnect() {
}

public void sendMessage(String message) {
// This check needs to be done, otherwise if the user would hit enter without a message,
// nothing would be sent and the program would disconnect and terminate
if(message.equals("")){
message = " ";
}

ByteBuffer buffer = ByteBuffer.allocate(512);
buffer.put(message.getBytes(Charset.forName("UTF-8")));
Expand All @@ -201,22 +220,6 @@ public void sendMessage(String message) {
props.setHeaders(customHeaders);

publishChannel.publishBasic(buffer, props, exchangeName, routingKey, false, false);
System.out.println("MESSAGE PUBLISHED: " + message);
System.out.println("-> MESSAGE PUBLISHED: " + message);
}

public static void main(String[] args) throws InterruptedException, URISyntaxException, IOException {
JavaAmqpClientDemo demo = new JavaAmqpClientDemo(new URI("wss://sandbox.kaazing.net/amqp091"), "guest", "guest");
System.out.println("Kaazing Java AMQP Demo App. Copyright (C) 2016 Kaazing, Inc.");
System.out.println("Type the message to send or <exit> to stop.");
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String text = console.readLine();
if (text.toLowerCase().equals("<exit>"))
break;
// Send as a text
demo.sendMessage(text);
}
demo.disconnect();
}

}
19 changes: 19 additions & 0 deletions j2se/java-jms-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This J2SE console app communicates over WebSocket with a JMS server via Kaazing

## Steps for building and running the project

- Install gradle: follow the steps [here](https://gradle.org/gradle-download/).

- Build the application using gradle

```bash
Expand All @@ -24,6 +26,23 @@ or
```
build\install\java-jms-demo\bin\java-jms-demo.bat
```
**NOTE:** The application can be run in the folowing ways:
- To connect to our defult URI:
```
/java-jms-demo
```
-To your own local Kaazing Gateway URI (ex: *ws://localhost:8000/jms*):
```
/java-jms-demo '{YOUR.GATEWAY.URI}'
```
- To use credentials with our default URI:
```
/java-jms-demo 'joe' 'welcome'
```
- If you have setup your gateway for authentification :
```
/java-jms-demo '{YOUR.GATEWAY.URI}' '{USERNAME}' '{PASSWORD}'
```

## Interact with Kaazing Java WebSocket Client API

Expand Down
2 changes: 1 addition & 1 deletion j2se/java-jms-demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'eclipse'
apply plugin: 'application'

sourceCompatibility = 1.8
mainClassName = 'com.kaazing.jms.client.demo.JavaJMSClientDemo'
mainClassName = 'com.kaazing.jms.client.demo.JMSDemoClientMain'


repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.kaazing.jms.client.demo;

import javax.jms.JMSException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;

/**
* Created by azaharia on 02.02.2017.
*/
public class JMSDemoClientMain {

public static void main(String[] args) throws InterruptedException, URISyntaxException, IOException, JMSException {
JavaJMSClientDemo demo = null;
switch (args.length){
case 0:
demo = new JavaJMSClientDemo(new URI("ws://sandbox.kaazing.net/jms"), "", "");
break;
case 1:
demo = new JavaJMSClientDemo(new URI(args[0]), "", "");
break;
case 2:
demo = new JavaJMSClientDemo(new URI("ws://sandbox.kaazing.net/jms"), args[0], args[1]);
break;
case 3:
demo = new JavaJMSClientDemo(new URI(args[0]), args[1], args[2]);
break;
default:
System.out.println("Possible usage of the Kaazing Java JMS Demo: \n" +
" 1. If you want to connect to our default URI: \n" +
" /java-jms-demo\n" +
" 2. If you want to connect to your own local Kaazing Gateway URI (ex: *ws://localhost:8000/jms*):\n" +
" /java-jms-demo '{YOUR.GATEWAY.URI}' \n" +
" 3. If you want to use authentication with our default URI: \n" +
" /java-jms-demo 'joe' `welcome` \n" +
" 4. If you have setup your gateway for authentication: \n" +
" /java-jms-demo '{YOUR.GATEWAY.URI}' '{USERNAME}' '{PASSWORD}' \n" +
"Please restart your the Kaazing Java JMS Demo and input the correct parameters as stated above!");
System.exit(1);
}
demo.handleConnection();
System.out.println("Kaazing Java JMS Demo App. Copyright (C) 2017 Kaazing, Inc.");
System.out.println("Type the message to send or <exit> to stop.");
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
System.out.print("User input: ");
while (true) {
String text = console.readLine();
if (text.equalsIgnoreCase("<exit>"))
break;
// Send as a text
demo.sendMessage(text);
}
demo.disconnect();
}

}
Loading