Products | Versions |
---|---|
TIBCO Streaming | 10 |
// // Copyright (c) 2010-2019 TIBCO Software Inc. All rights reserved. // // SBReady waits for that target server and container to be running and then terminates. // Console output may be configured using a logback.xml file. // // Usage: java -Dlogback.configurationFile=./logback.xml -jar sbready.jar sb://localhost:10001 default // Output example: // 2018-12-06 16:03:46 [INFO] SBReady - args -- uri:'sb://127.0.0.1:10001' container:'default' // 2018-12-06 16:03:47 [INFO] SBReady - StreamBase container 'default' ready at sb://127.0.0.1:10001 // package com.tibco.sb.support; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.streambase.sb.StreamBaseException; import com.streambase.sb.client.StreamBaseClient; public class SBReady { // The time to wait before retrying to connect to StreamBase, milliseconds private final static long TEST_RETRY_INTERVAL = 500; public SBReady() { } public static void main(String[] args) { Logger logger = LoggerFactory.getLogger(SBReady.class); String uri = null; String container = null; if (args.length == 2) { uri = args[0]; container = args[1]; } if (uri==null || container==null) { logger.info("Usage: sbready {sburi} {container}"); logger.info(" sburi: sb://host[:port]"); logger.info(" container: default, system, ..."); System.exit(1); } // emit start time and args logger.info("SBready: uri='"+uri+"' container='"+container+"'"); StreamBaseClient client = null; boolean found = false; // loop until the container exists at the target uri while (!found) { // if not connected, try to connect if (client==null) { try { // if no exception, then success client = new StreamBaseClient(uri); } catch (StreamBaseException e1) { client=null; } } // if connected, check for existence of target container if (client!=null) { try { for (String cont : client.listEntities(com.streambase.sb.EntityType.CONTAINER)) { if(cont.matches(container)) { found = true; } } if (found) { client.close(); break; } } catch (StreamBaseException e) { client = null; } } // delay if not found if (!found) { try { Thread.sleep(SBReady.TEST_RETRY_INTERVAL); } catch (InterruptedException interruptedException) { // This can be ignored. } } } // emit success and exit logger.info("StreamBase container '"+container+"' ready at " + uri); } }Logging configuration, logback.xml:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%date{yyyy-MM-dd HH:mm:ss} [%level] %logger{0} - %msg%n</pattern> </encoder> </appender> <root level="INFO"> <appender-ref ref="console" /> </root> </configuration>
These are the general setup steps to build a StreamBase Java API Client application in TIBCO StreamBase Studio, with the above SBReady client as an example.
In SB Studio:
1. Use menu: File > New > Other... > Maven > Maven Project. Click Next.
2. In the "New Maven Project" dialog, select "Create a simple project (skip archetype selection)". Click Next.
3. Provide Group Id, Artifact Id, Name, and Description (example):
Group Id: com.tibco.sb.support
Artifact Id: sbready
Name: sbready
Description: SB Ready Client
4. The default Packaging is 'jar' which is correct for this project. Click Finish.
5. In the Project Explorer, right-click folder sbready > src/main/java, choose New > Class.
6. Set:
Source folder: sbready/src/main/java
Package: com.tibco.sb.support (or your organization)
Name: SBReady
7. In "Which method stubs...", set "public static void main(String[] args)". Click Finish.
8. Replace SBReady.jar file contents with the source above. Save. There will be errors.
9. Open the project pom.xml file.
10. On the "pom.xml" tab, add <dependencies> after </description>:
<dependencies> <dependency> <groupId>com.tibco.ep.sb</groupId> <artifactId>client-core</artifactId> <version>10.4.0</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> </dependency> </dependencies>
This will add these libraries as dependencies and the errors in SBReady.java should go away:
client-core-10.4.0.jar client-deps-10.4.0.jar fastjson-1.2.8.jar icu4j-58.2.jar logback-classic-1.2.3.jar logback-core-1.2.3.jar slf4j-api-1.7.21.jarIt is the responsibility of the deployment engineer to copy these libraries from the Maven repository into a classpath location on the end-user's system. Similarly, the logback.xml file will need to be placed on the end-user system as well.
For ease of use, create a shell-script or batch-file for this command.
Example output using logback.xml
2018-12-12 11:41:39 [INFO] SBReady - SBready: uri='sb://127.0.0.1:10001' container='default'
2018-12-12 11:43:05 [INFO] SBReady - StreamBase container 'default' ready at sb://127.0.0.1:10001
Example output without custom logging:
11:38:52.126 [main] INFO com.sb.support.SBReady - SBReady: uri='sb://127.0.0.1:10001' container='default'
11:39:31.103 [main] DEBUG com.streambase.sb.client.StreamBaseClient - StreamBase client finished normally
11:39:31.106 [main] INFO com.sb.support.SBReady - StreamBase container 'default' ready at sb://127.0.0.1:10001
Deployment may be simplified by creating a runnable "fat" jar which contains all necessary dependencies. This allows for only two files to be copied to the end-user's system, sbready.jar and logback.xml.
1. Add the maven assembly plugin <build> after </dependencies>:
<build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>com.sb.support.SBReady3</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build>2. Use: Run as > Maven build..., Goals = "package assembly:single"