Wowza Community

Sample Java class for creating a command line interface to control Wowza Media Server

My system is Linux, and java is in

/usr/lib64/jvm/java/bin

i copied this code an pasted to a file called JMXCommandLine.java. Then i run this command

 javac JMXCommandLine.java 

it didn’t gave any errors. It created .class file.

linux-l6al:/usr/lib64/jvm/java/bin # ls -lrt | tail            
-rwxr-xr-x 1 root root  51619 Apr 13  2010 extcheck            
-rwxr-xr-x 1 root root  51872 Apr 13  2010 apt                 
-rwxr-xr-x 1 root root  51987 Apr 13  2010 appletviewer        
-rwxr-xr-x 1 root root   6347 Apr 13  2010 jcontrol            
-rwxr-xr-x 1 root root  92954 Apr 13  2010 javaws              
-rwxr-xr-x 1 root root     96 Jul  6  2010 HtmlConverter       
lrwxrwxrwx 1 root root      8 Apr 18 19:31 ControlPanel -> jcontrol
-rw-r--r-- 1 root root  18099 Jun 21 11:29 JMXCommandLine.java     
-rw-r--r-- 1 root root   1505 Jun 21 11:29 JMXCommandLine$AppConextName.class
-rw-r--r-- 1 root root  11441 Jun 21 11:29 JMXCommandLine.class              
linux-l6al:/usr/lib64/jvm/java/bin #

When i run for usage help it showed me this.

linux-l6al:/usr/lib64/jvm/java/bin # java -cp . JMXCommandLine $@
Usage:
[command] -[switch [value]...] [command] [params...]
Switches:
  -jmx  [jmx-url]
  -user [jmx-username]
  -pass [jmx-password]
Commands:
  getServerVersion
  startVHost [vhost]
  stopVHost [vhost]
  reloadVHostConfig
  startAppInstance [vhost:application/appInstance]
  touchAppInstance [vhost:application/appInstance]
  shutdownAppInstance [vhost:application/appInstance]
  startMediaCasterStream [vhost:application/appInstance] [stream-name] [mediacaster-type]
  stopMediaCasterStream [vhost:application/appInstance] [stream-name]
  resetMediaCasterStream [vhost:application/appInstance] [stream-name]
  getConnectionCounts
  getConnectionCounts [vhost:application/appInstance]
  getConnectionCounts [vhost:application/appInstance] [stream-name]
  getIOOutByteRate
  getIOOutByteRate [vhost:application/appInstance]
  getIOInByteRate
  getIOInByteRate [vhost:application/appInstance]
linux-l6al:/usr/lib64/jvm/java/bin #

Now when i am executing with options it gave this error.

linux-l6al:/usr/lib64/jvm/java/bin # java -cp . JMXCommandLine -user admin -pass password getServerVersion
ERROR: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
        java.net.ConnectException: Connection refused]
linux-l6al:/usr/lib64/jvm/java/bin #
linux-l6al:/usr/lib64/jvm/java/bin #
linux-l6al:/usr/lib64/jvm/java/bin # java -cp . JMXCommandLine getServerVersion
ERROR: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
        java.net.ConnectException: Connection refused]
linux-l6al:/usr/lib64/jvm/java/bin #

As i am not of programing background, What this errors are corresponds to ?

All i need is a way to start and stop the streams using command line tool…

And if my URL is

 rtmp://192.168.1.123:1935/testlive/testlive.stream

, whet should be the correct sequence to start stop stream using this app.

Thanks,

Shekar

Shekar,

Make sure Wowza is running.

Make sure /conf/Server.xml /JMXRemoteConfiguration /Enable is set to “true”

Make sure you /conf/jmxremote.access and jmxremote.password have user “admin” and password “admin” with readwrite privileges.

Richard

The example in the guide is:

to start stream:
jmxcl [jmx-connection-switches] touchAppInstance live
jmxcl [jmx-connection-switches] startMediaCasterStream live myStream.sdp rtp

Not sure where you are going after that.

Richard

Shekar,

I haven’t used this method very much, but I think the way to discover the commands and parameters is look at JConsole and find the Operations screens.

https://www.wowza.com/docs/quick-start-guides

Richard

Thanks for the reply Richard. Glad now i can make this working ( getServerViersion method is working it is showing me

Wowza Media Server 2 Subscription 2.2.4 build27452

hope its latest… )

Now how do i start/stop the stream? when i tried i get this error.

linux-l6al:/etc/alternatives/java_sdk/bin # java -cp . JMXCommandLine  -user admin -pass admin startMediaCasterStream testlive  testlive.stream rtp
startMediaCasterStream testlive testlive.stream rtp
ERROR: doInvoke: javax.management.InstanceNotFoundException: WowzaMediaServerPro:vHosts=VHosts,vHostName=_defaultVHost_,applications=Applications,applicationName=testlive,applicationInstances=ApplicationInstances,applicationInstanceName=_definst_,name=ApplicationInstance
linux-l6al:/etc/alternatives/java_sdk/bin #

But i can play the url

rtmp://localhost:1935/testlive/testlive.stream

Any idea?

Actually i wanted to use “liverepeater-record” method in origin (for vod kind of streaming), and record the particular incoming stream every hrs, and the use the smil to stream them separately… which method is suitable ? is it

startAppInstance    OR startMediaCasterStream ? 

as everything stream started/stoped it creates an mp4 file …

Thanks.

How do i find out which is the correct format?

Can the guy who developed reply for this?

Thanks,

Shekar