Skip to content

Commit

Permalink
chore: revert trailing spaces edits
Browse files Browse the repository at this point in the history
My IDE is set up to remove trailing whitespace so I accidentally
made a bunch of style/formattinng changes I hadn't intended to
commit.

Signed-off-by: Dale Lane <[email protected]>
  • Loading branch information
dalelane committed Oct 24, 2021
1 parent 9f8125f commit dbbda72
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 89 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ To run the generated Java project in a Docker container, use the commands as bel
1. Build the image
```
docker build -t [PACKAGE_NAME]:[VERSION] .
```
```

2. Run the image in detached mode
```
docker run -d [PACKAGE_NAME]:[VERSION]
```
docker run -d [PACKAGE_NAME]:[VERSION]
```

For further information including network setup, please see the [tutorial](template/TUTORIAL.md).

Expand Down
18 changes: 9 additions & 9 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cd ~/asyncapi-java-tutorial
```

## Running the Publisher/Subscriber Template
These commands will allow you to run the Java Template publisher/subscriber model using IBM MQ.
These commands will allow you to run the Java Template publisher/subscriber model using IBM MQ.
1. Run the AsyncAPI Generator. <br>**Note:** You may need to change the username and password values if you have not followed the IBM MQ tutorial.
```
ag https://ibm.biz/mq-asyncapi-yml-sample https://ibm.biz/mq-asyncapi-java-template -o ./output -p server=production -p user=app -p password=passw0rd
Expand All @@ -44,7 +44,7 @@ These commands will allow you to run the Java Template publisher/subscriber mode
```
3. Install the dependencies required to run this template
```
mvn compile
mvn compile
```
4. Create .jar package using maven
```
Expand All @@ -54,7 +54,7 @@ These commands will allow you to run the Java Template publisher/subscriber mode
```
java -cp target/asyncapi-java-generator-0.1.0.jar com.ibm.mq.samples.jms.DemoSubscriber
```
6. In a seperate terminal, navigate to the `output` directory above and run your generated Publisher
6. In a seperate terminal, navigate to the `output` directory above and run your generated Publisher
```
cd ~/asyncapi-java-tutorial/output
java -cp target/asyncapi-java-generator-0.1.0.jar com.ibm.mq.samples.jms.DemoProducer
Expand All @@ -79,27 +79,27 @@ To deploy a dockerised instance of this project;
1. Build the image
```
docker build -t [PACKAGE_NAME]:[VERSION] .
```
```
2. Run the image in detached mode
```
docker run -d [PACKAGE_NAME]:[VERSION]
```
```
Please note; The default `Dockerfile` included in output will only run `DemoSubscriber.java`. This will need to be replaced with the entrypoint to your application.
Please note; The default `Dockerfile` included in output will only run `DemoSubscriber.java`. This will need to be replaced with the entrypoint to your application.
### Networking
Docker networking needs to be properly configured in order to allow your project to connect to an MQ instance.
Docker networking needs to be properly configured in order to allow your project to connect to an MQ instance.
If MQ is also running in a docker container
1. Create a docker network
```
docker network create exampleMqNetwork
```
```
2. Attach the docker network to your MQ container
```
docker network connect exampleMqNetwork
```
```
3. Update your env.json server hostname to match the container name for MQ. To find the name run
```
docker ps
Expand Down
10 changes: 5 additions & 5 deletions components/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { createJavaArgsFromProperties } from '../utils/Types.utils';

export function Class({ childrenContent, name, implementsClass, extendsClass }) {
if (childrenContent === undefined) {
if (childrenContent === undefined) {
childrenContent = '';
}

Expand Down Expand Up @@ -73,17 +73,17 @@ export function getMqValues(url, val) {
}

const splitVals = regString.toString().split('/');
if (splitVals.length === 2) {
if (splitVals.length === 2) {
if (val === 'qmgr')
return splitVals[0];
if (val === 'mqChannel')
return splitVals[1];

throw new Error('Invalid parameter passed into getMqValues function');
}
throw new Error('Invalid URL passed into getMqValues function');
}

export function URLtoHost(url) {
const u = new URL(url);
return u.host;
Expand Down Expand Up @@ -154,7 +154,7 @@ import ${params.package}.models.${messageName.charAt(0).toUpperCase() + messageN
/* Used to resolve a channel object to message name */
export function ChannelToMessage(channel, asyncapi) {
// Get payload from either publish or subscribe
const targetPayloadProperties = Object.prototype.hasOwnProperty.call(channel, 'publish') ?
const targetPayloadProperties = Object.prototype.hasOwnProperty.call(channel, 'publish') ?
channel.publish().message().payload().properties() :
channel.subscribe().message().payload().properties();

Expand Down
4 changes: 2 additions & 2 deletions components/Consumer/MQConsumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function ReceiveMessage({ message }) {
* Implement your business logic to handle
* received messages here.
*/
} catch (JMSException jmsex) {
recordFailure(jmsex);
} catch (JsonProcessingException jsonproex) {
Expand All @@ -101,7 +101,7 @@ export function ReceiveMessage({ message }) {
}
`;
}

export function ConsumerConstructor({ name }) {
return `
super();
Expand Down
10 changes: 5 additions & 5 deletions components/Files/Consumers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ export function Consumers(asyncapi, channels, params) {
const packagePath = javaPackageToPath(params.package);

const message = ChannelToMessage(channel, asyncapi);

if (channel.subscribe()) {
return (
<File name={`${packagePath}${className}.java`}>
<PackageDeclaration path={params.package}></PackageDeclaration>
<ConsumerImports asyncapi={asyncapi} params={params} message={message}></ConsumerImports>

<Class name={className} extendsClass="PubSubBase">
<ConsumerDeclaration asyncapi={asyncapi} params={params} name={channelName} />

<ClassConstructor name={className}>
<ConsumerConstructor asyncapi={asyncapi} params={params} name={name}/>
</ClassConstructor>
Expand All @@ -45,8 +45,8 @@ export function Consumers(asyncapi, channels, params) {

<ConsumerClose asyncapi={asyncapi} params={params} />
</Class>
</File>
</File>
);
}
});
}
}
6 changes: 3 additions & 3 deletions components/Files/Producers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export function Producers(asyncapi, channels, params) {
if (channel.publish()) {
return (
<File name={`${packagePath}${className}.java`}>

<PackageDeclaration path={params.package} />
<ProducerImports asyncapi={asyncapi} params={params} />
<ImportModels messages={messages} params={params} />

<Class name={className} extendsClass="PubSubBase">
<ProducerDeclaration asyncapi={asyncapi} params={params} />

<ClassConstructor name={className}>
<ProducerConstructor asyncapi={asyncapi} params={params} name={name} />
</ClassConstructor>
Expand Down
2 changes: 1 addition & 1 deletion components/PomHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function PomHelper({ server, params }) {
// Resolve additional dependencies depending on protocol supplied
const supportedProtocol = server.protocol();
const dependencies = resolveDependencies(supportedProtocol);

let protocolDependencies = '';

for (const dependency of dependencies) {
Expand Down
16 changes: 8 additions & 8 deletions components/Producer/MQProducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ export function ProducerDeclaration() {

export function SendMessage() {
return `
public void send(ModelContract modelContract) {
public void send(ModelContract modelContract) {
Serializable modelInstance = (Serializable) modelContract;
try{
// JSON encode and transmit
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(modelInstance);
logger.info("Sending Message: " + json);
this.producer.send(destination, json);
}catch (JsonProcessingException e){
logger.severe("An error occured whilst attempting to send a message: " + e);
}
}`;
}

export function ProducerConstructor({ name }) {
return `
super();
Expand Down Expand Up @@ -81,9 +81,9 @@ import ${params.package}.Connection;
import ${params.package}.PubSubBase;
import ${params.package}.models.ModelContract;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.annotation.JsonView;
`;
}
}
46 changes: 23 additions & 23 deletions components/PubSubBase/MQPubSubBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ function getPubSubContent(params) {
import java.util.Map;
import java.util.List;
import java.nio.file.Paths;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import ${params.package}.ConnectionHelper;
import ${params.package}.LoggingHelper;
import javax.jms.Destination;
import javax.jms.JMSContext;
import javax.jms.JMSRuntimeException;
import javax.jms.JMSException;
public class PubSubBase {
protected static final Logger logger = Logger.getLogger("${params.package}");
protected ConnectionHelper ch = null;
protected JMSContext context = null;
protected Destination destination = null;
Expand All @@ -49,25 +49,25 @@ function getPubSubContent(params) {
public void Base(){
LoggingHelper.init(logger);
}
public void createConnection(String topicName, String id){
// Retrieve first MQ endpoint from env.json
List<Map> MQ_ENDPOINTS = null;
Map MQFirst = null;
try {
ObjectMapper mapper = new ObjectMapper();
// Convert JSON file to map
Map<Object, List<Map>> map = mapper.readValue(Paths.get("env.json").toFile(), Map.class);
MQ_ENDPOINTS = map.get("MQ_ENDPOINTS");
// TODO : Allow switching between multiple endpoints
MQFirst = MQ_ENDPOINTS.get(0);
} catch (Exception ex) {
ex.printStackTrace();
}
// Create connection definition from env variables
Connection myConnection = new Connection(
MQFirst.get("HOST").toString(),
Expand All @@ -79,26 +79,26 @@ function getPubSubContent(params) {
null,
topicName,
null);
// Build connection helper
ch = new ConnectionHelper(id, myConnection);
logger.info("created connection factory");
// Create context and set local topic destination
context = ch.getContext();
logger.info("context created");
destination = ch.getTopicDestination();
logger.info("destination created");
}
public void close() {
ch.closeContext();
ch = null;
}
protected void recordFailure(Exception ex) {
if (ex != null) {
if (ex instanceof JMSException) {
Expand All @@ -108,24 +108,24 @@ function getPubSubContent(params) {
}
}
}
protected void processJMSException(JMSException jmsex) {
logger.warning(jmsex.getMessage());
Throwable innerException = jmsex.getLinkedException();
logger.warning("Exception is: " + jmsex);
if (innerException != null) {
logger.warning("Inner exception(s):");
}
while (innerException != null) {
logger.warning(innerException.getMessage());
innerException = innerException.getCause();
}
return;
}
}
`;
}

Expand Down
4 changes: 2 additions & 2 deletions components/demo/DemoProducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

/*
* Here you can see example of complex operations.
/*
* Here you can see example of complex operations.
* You can actually do whatever you want. It is important that the value returned from the function must be a string or a component.
*/

Expand Down
8 changes: 4 additions & 4 deletions components/demo/DemoSubscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

/*
* Here you can see example of complex operations.
/*
* Here you can see example of complex operations.
* You can actually do whatever you want. It is important that the value returned from the function must be a string or a component.
*/

Expand All @@ -31,12 +31,12 @@ public class DemoSubscriber {
public static void main(String[] args) {
// Create a subscriber instance to connect to the server
${className}Subscriber consumer = new ${className}Subscriber();
// Receive updates for this queue indefinitely
consumer.receive(TIMEOUT);
// Close the connection
consumer.close();
}
}`;
}
}
Loading

0 comments on commit dbbda72

Please sign in to comment.