After a long time searching on the internet, I finally found how to create users on RabbitMQ programmatically. Basically, you have to send a HTTP request with PUT or POST "status". Since I'm developing on Java Web, I could easily find a Java library to support me. I used Apache HTTP library, you can find it here:
http://hc.apache.org/downloads.cgi
So, my Java code it's posted below:
For libs, imports:
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.commons.codec.binary.Base64;
The code to create a new User:
// First, save your user/pw with permission to create new users.
// NOTE: this user is already created on RabbitMQ with permission to create new users
String enc = new String( Base64.encodeBase64( "USER_NAME_WITH_PERMISSION:PASS_W".getBytes() ) );
try{
HttpPut putCriaUsuario = new HttpPut( "http://RABBIT_MQ_IP:PORT/api/users/USER_NAME_TO_CREATE );
putCriaUsuario.addHeader( "Authorization", "Basic " + enc ); // RabbitMQ requires a user with create permission, create it mannually first
putCriaUsuario.addHeader( "content-type", "application/json" );
putCriaUsuario.setEntity( new StringEntity( "{\"password\":\"YOUR_PASS_WORD\",\"tags\":\"none\"}" ) );
client.execute( putCriaUsuario );
//After create, configure RabbitMQ permissions
HttpPut putConfiguraPermissoes = new HttpPut( "http://RABBIT_MQ_IP:PORT/api/permissions/QUEUE_NAME/USER_NAME_CREATED" );
putConfiguraPermissoes.addHeader( "Authorization", "Basic " + enc );
putConfiguraPermissoes.addHeader( "content-type", "application/json" );
putConfiguraPermissoes.setEntity( new StringEntity( "{\"configure\":\"^$\",\"write\":\".*\",\"read\":\".*\"}" ) ); // Permission you wanna. Check RabbitMQ HTTP API for details
client.execute( putConfiguraPermissoes );
}catch( UnsupportedEncodingException ex ){
ex.printStackTrace();
}catch( IOException ex ){
ex.printStackTrace();
}
This is Java, so it can be used on desktop application or Java Web. On other language follows the same logic, just with another libs. Hope it help us all. Fells happy for sharing knowledge!